- Home /
on button hover box shows
Hi, i was wondering how i can code so if someone have theirs mouse over a button it shows a GUI Box and a GUI Button? hope to get a nice reply
Thanks
Answer by LijuDeveloper · Oct 24, 2013 at 09:56 AM
This is sample code for Mouse Over Mesh Or Button
using UnityEngine;
using System.Collections;
public class Example : MonoBehaviour
{
public bool boolMouseOver = false ;
void OnMouseOver() // This Function for Mouse Over a Mesh or GUIContent
{
boolMouseOver = true;
}
void OnMouseExit() // This Function for Mouse Not Over a Mesh or GUIContent
{
boolMouseOver = false;
}
void OnGUI()
{
GUI.depth = -10;
GUI.Button(new Rect(10, 10, 100, 20), new GUIContent("Click me", "Mouse Over Button")); // When Mouse Over this button GUI.tooltip = "Mouse Over Button"
if(GUI.tooltip =="Mouse Over Button")
{
boolMouseOver = true;
}
else
{
boolMouseOver = false;
}
if(boolMouseOver == true)
{
GUI.Box (new Rect(500,100,100,50) ,"Here is a box");
GUI.Box (new Rect(100,100,100,50) ,"Here is a Button");
}
}
For More details about Mouse Over read this link
http://answers.unity3d.com/questions/15508/mouseover-detection.html
Answer by MrYOLO · Oct 24, 2013 at 08:25 AM
there's some functions you can use for to detect input Functions. I got two solutions for this: 1. you get the mouse position and see if it is in the button area. 2. use collider and raycast to detect if the user hover upon the button. Then you can shows the GUI Box(Button).
Your answer
Follow this Question
Related Questions
Weird GUI problem 1 Answer
How can I Include string variables in Rich Text? 1 Answer
In game Escape menu displays all the time 1 Answer
Can I make my GUI Buttons appear OVER a GUI Window? 1 Answer
How to make GUI button glow 0 Answers