Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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 like this:

enter image description here

But i want it to be show that GUI hovering button on that character, not when the character selected.

Thank you

share|improve this question
add comment

1 Answer

You can only call GUI functions inside void OnGUI(). So, make a boolean to indicate when the mouse is hovering on a character and flag that bool as true. Then in the OnGUI you have that tooltip wrapped:

void OnGUI()
{
    if(showCharToolTip)
    {  
                if (GUI.Button(buttonRect, "This is player 1"))
                {
                }
    }
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.