- Home /
How to do different actions when hovering mouse at each button on GUILayout
I made a button list similar to the one below:
GUI.BeginGroup(rect);
GUILayout.Button("Level 1");
GUILayout.Button("Level 2");
GUILayout.Button("Level 3");
GUILayout.Button("Level 4");
GUI.EndGroup()
What I want to do is show an image on GUI which changes depending on which button my mouse cursor is over. For example, if my cursor is over Level 1 button, the GUI shows a level 1 preview. Then if I move it into Level 3 it changes to a level 3 preview, and so goes on. Problem is I cant figure a way to do this without getting errors or even doing something!!
Answer by Eric5h5 · Apr 11, 2013 at 10:30 PM
Use GUI.tooltip. A tooltip can only be a string, but you can check the string and display different images depending on the value. (A bit of hack, but it works.)
Works perfectly, thanks a lot! :D
Just to clarify for those who didnt get it, you can add a tooltip to the buttons on the format below:
GUILayout.Button(new GUIContent("Text or Image", "Tooltip"));
Then you can simply use switch(GUI.tooltip) to specify the events.
Your answer
Follow this Question
Related Questions
Detect touches on the top right corner of the screen 1 Answer
i was wondering about gui hover... 3 Answers
Can I use GUIStyle and make the button's textures MovieTextures instead of regular 2D Textures? 0 Answers
How do I detect a mouse hover? 1 Answer
Avoid new lines between elements inside a EditorWindow 1 Answer