Im doing an inventory for a game, and i wanted it to be controlled by the keyboard and mouse, Is it possible to access to the functionality of a button like doing a hover or pressing it using only code?
I was looking to make a "Button" or "Toolbar" variable but it seems that it cant be done.
Any help is well received.
will tell you if the mouse is in a rectangle. If you make that the same rectangle as you drew the control, you can tell if the mouse is hovering over the control
If you're using GUILayout, the
function will give you the Rect of the last control drawn.
answered Sep 21 '10 at 09:11 PM
Good information you are providing. Maybe we should mention that OnGUI is called more than once per Frame. e.g. there is a Repaint and Layout-Call. If you want to check for hovering like HeywoodFloyd described, it seems you have to do this in the Repaint-OnGUI call:
Another thing to mention. Do use Event.current.mousePosition! It is not the same as Input.mousePosition!
answered Nov 02 '10 at 08:35 PM