- Home /
Show the GUI button when mouse hover to the object
Hai, i already have this player on my screen. And i want, whenever the mouse hover at the object, the GUI button show itself (like tooltip). I tried below code, but the button is not showed up when i hover at the object. Here is my code:
void OnMouseEnter()
{
Rect buttonRect = new Rect(250, Screen.height - buttonHeight, textInfoPlayerButtonWidth, textInfoPlayerButtonHeight);
if (GameManager.instance.currentPlayerIndex == 0) (the object)
{
if (GUI.Button(buttonRect, "This is player 1"))
{
}
}
}
I want to be it like this:
But i want it to be show that GUI hovering button on that character, not when the character selected.
Thank you
Answer by belvita · Nov 30, 2013 at 09:01 AM
u can use this
if( Physics.Raycast( ray,out hit) )
{
if(hit.collider.gameObject.tag=="urcharacter")
{
oncharacter=true;
}
else{
oncharacter=false;
}
private void OnGUI()
{
if(oncharacter==true)
{
// Make a background box,//x position ,y position width and wide
GUI.Box(new Rect(Screen.width / 2-75, Screen.height / 2-160, 200, 100), "");
//if the button is pressed means if exists
if(GUI.Button(new Rect (Screen.width / 2-75,Screen.height / 2-160,30,30),sand))
{
so hop u get the idea .please vote me if u get it work
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Need help cycling through an array with a 'for' loop. 0 Answers
On Mouse Click Button event 0 Answers
Turn Based RPG Combat System Style Game 0 Answers