I have been reading some of the posts about GUI events and it seems that the GUI.Button does not generate any events for the user. Is this really true? It seems like the engine internally detects this events because it is capable to change the texture and color of the buttons when going over it through the GUIStyles. Then why we are not able to catch these events on script? Any nice solution for this?
You can use GUITextures instead, which respond to OnMouseOver() etc. With OnGUI, you can simulate this by manually checking Rect values and setting GUIStyles as appropriate.
Thank you Eric. To make this cleaner I did a class called GUIButton that contains a GUI.Button and sends the events OnButtonClick, OnButtonenter and OnButtonExit to a registered class. All this using the Rect.Contains of course
The whole Cursor and OnMouse system is a total mess. Whatever you choose to use as your button class, you loose something else that is normally a common functionality in any other application.
So when great programmers (such as yourselves) come up with workaround scripts, the rest of us would be much obliged if you could post a working example when you have one. We can then point other folks who experience the same problem to one single forum topic.
Unity’s GUI system is pretty cool but we never used it since it’s extremly mouse based and doesn’t support other devices like keyboard and game-controllers as well.
But sometimes your code might be even faster and more flexible than build-in solutions. Just give it a try and create the code that matches your needs!