- Home /
GUI.Button on MouseHover
What i want is a script that will allow me to have GUI.Buttons/Boxes appear when i hover my mouse over a text with a collider. The text already has a script about change of colour when hovered over and a sound player(on hover), is there a way to make a gui appear too?
I tried experimenting (with my little knowledge) but didn't work out. Any help?
unable to getting you, describe clearly, what you want?
Answer by Landern · Nov 27, 2012 at 03:18 PM
Implement you GUI in the OnGUI function/method as you normally would, set a variable out side of the scope of the function like:
//js:
private var imOverYouBro:boolean = false;
//cs field:
private bool imOverYouBro = false;
In your function/method where you change the color of the text or something similar that is triggered by the hover event, set the above var to true.
Wrap your GUI in an if statement that evaluates the imOverYouBro boolean var.
// js
function OnGUI(){
if(imOverYouBro)
{
// ... bunches of gui stuff
}
}
// cs
void OnGUI()
{
if(imOverYouBro)
{
// ... bunches of gui stuff
}
}
When the mouse is no longer hovering(exit), set the same var to false.
Something like that.
Your answer
Follow this Question
Related Questions
How to check if player is hovering mouse over a GUI Box 3 Answers
How to make a Hover event on GUI.Button 6 Answers
Is Mesh Collider Optimal for GUI? 2 Answers