- Home /
On button hover, Gui Box shows, on box hover, Gui Box shows
Hello so i was gonna design my menu for my game and wanted so if someone have their mouse over a button its shows a gui box with 3 or 4 buttons in it but i cant figure how i can doe so if people move the mouse to the gui box than it doesent dissapear here is my code:
public bool boolMouseOver = false;
GUI.Button(new Rect(Screen.width / 2 - 380, Screen.height / 2 - 130, 200, 50), new GUIContent("MENU", "Mouse Over Button"), style);
if (GUI.tooltip == "Mouse Over Button")
boolMouseOver = true;
else
boolMouseOver = false;
if (boolMouseOver == true)
{
GUI.Box(new Rect(Screen.width / 2 - 180, Screen.height / 2 - 130, 220, 300), new GUIContent("", "Mouse Over Button"));
if (GUI.Button(new Rect(Screen.width / 2 - 160, Screen.height / 2 - 125, 180, 40), "1", style))
{
audio.PlayOneShot(buttonsound);
}
if (GUI.Button(new Rect(Screen.width / 2 - 160, Screen.height / 2 - 75, 180, 40), "2", style))
{
audio.PlayOneShot(buttonsound);
}
if (GUI.Button(new Rect(Screen.width / 2 - 160, Screen.height / 2 - 25, 180, 40), "3", style))
{
audio.PlayOneShot(buttonsound);
}
}
Comment
Best Answer
Answer by LijuDeveloper · Oct 31, 2013 at 07:17 AM
Try this code
using UnityEngine;
using System.Collections;
public class Example : MonoBehaviour
{
public bool boolMouseOver ;
public GUISkin MyGUISkin;
void OnGUI()
{
if(boolMouseOver == true )
{
GUI.Box(new Rect(Screen.width / 2 - 190, Screen.height / 2 - 140, 240, 320), new GUIContent("", "Mouse Exit Button") ,MyGUISkin.customStyles[0] );// Exit GUI Box ,MyGUISkin.customStyles[0] must be transparent png or nothing
GUI.Box(new Rect(Screen.width / 2 - 180, Screen.height / 2 - 130, 220, 300), new GUIContent("", "Mouse Over Box") ,MyGUISkin.customStyles[1]);// Original box
if (GUI.Button(new Rect(Screen.width / 2 - 160, Screen.height / 2 - 125, 180, 40), "1" ))
{
}
if (GUI.Button(new Rect(Screen.width / 2 - 160, Screen.height / 2 - 75, 180, 40), "2" ))
{
}
if (GUI.Button(new Rect(Screen.width / 2 - 160, Screen.height / 2 - 25, 180, 40), "3" ))
{
}
}
GUI.Box(new Rect(Screen.width / 2 - 390, Screen.height / 2 - 140, 210, 70), new GUIContent("", "Mouse Exit Button") ,MyGUISkin.customStyles[0] );// Mouse Exit BoxMyGUISkin.customStyles[0] must be transparent png or nothing
GUI.Button(new Rect(Screen.width / 2 - 380, Screen.height / 2 - 130, 200, 50), new GUIContent("MENU", "Mouse Over Button"),MyGUISkin.customStyles[1] );// Menu Button
if (GUI.tooltip == "Mouse Over Button")
{
boolMouseOver = true;
}
if(GUI.tooltip == "Mouse Exit Button")
{
boolMouseOver = false;
}
}
}