|
How to know if mouse is over a GUI.button. I want to press 1-8 while my mouse is over a skill icon to assign shortcut to it.
(comments are locked)
|
|
Something like this should work. I haven't tested it (so there could be typos), but this is the general idea. You need to adjust the y-coordinate of the mouse position because the GUI uses a different screen coordinate system: Y = 0 is at the top of the screen. Thanks. Although it is a bit manual way, but I guess it may just be solution for it until Unity add mouse over function to GUI.button.
May 17 '11 at 03:02 AM
Dreamer
(comments are locked)
|
|
jahroy has answered this, even though I'm a bit confused about why one wants a Here is my suggestion: I typically use functions to generate rectangles for my GUI elements because I almost always need to create them dynamically... Either because they're based on screen resolution or because their size/location is dependent on other GUI elements. Example: I need to draw a button directly next to a label that is resizeable and not always visible. I would use a function to create the label's rectangle. That way the code that draws the button can know where the label is. Not relevant here, but a good idea in my opinion. Besides, who wants to look at a bunch of hard-coded rectangles in their code!
May 16 '11 at 07:06 PM
jahroy
Also, I believe that using Event.current.keyCode from the OnGUI function could potentially cause your code to execute multiple times for the same key press. I would recommend checking for keyboard input from Update() using one of the Input.GetKeyDown functions. Drawing a button from one function and checking for keyboard input in a different function is yet another reason why getButtonRectangle is a good idea!
May 16 '11 at 07:11 PM
jahroy
True true, you would create methods for more complex types of GUI elements. However, as you say, not relevant in this case. However, I'm not that much for creating new Rects each time OnGUI is called, since it could be several types each frame.
May 16 '11 at 07:51 PM
Ejlersen
True again, one could just use Event.Use() for that situation. Besides I have seen a few situations where Unity doesn't capture Input in IE 8, because of the security settings. But, thats besides the point. I have the feeling, that you think I'm attacking your way of thinking about creating GUI in Unity. Really I'm not.
May 16 '11 at 07:56 PM
Ejlersen
No worries. I did not feel that your post was an attack. Just wanted to explain my post. -- Regarding the Event.Use function... That's awesome, thanks! I didn't know about that one. I may go change some of my code now. That's better than using the Update method.
May 16 '11 at 08:42 PM
jahroy
(comments are locked)
|
