1
\$\begingroup\$

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

\$\endgroup\$
1
\$\begingroup\$

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"))
                {
                }
    }
}
|improve this answer|||||
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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