0

in my game I have several house groups (see image below), I want to show a specific message when the mouse hovers a specific house group.

For some reason, this only works on the first switch case (house) but fails on the second switch (house2). The default case doesn't work either. I verified that the case house2 is found by the engine. By not working I mean the text does not appear.

Do you have any idea about the problem? Image: Image Code: public class MouseIsOver : MonoBehaviour {

private Image TipImage;
private Text textObject;
public string text;
private bool displayInfo;

void Start ()
{
    TipImage = GameObject.Find("realtyInformation").GetComponent<Image>();
    textObject = GameObject.Find("realtyInformationText").GetComponent<Text>();
    TipImage.enabled = false;
}

{
    Display();
}

private void OnGUI()
{

}

void Display ()
{
    if (displayInfo)
    {
        switch (text.ToLower())
        {
            case "house":
                textObject.text = "house text1";
                break;
            case "house2":
                textObject.text = "house text2";
                break;
            default:
                textObject.text = "Click on the building";
                break;
        }

    }
    else
    {
        TipImage.enabled = false;
        textObject.text = "";
    }
    TipImage.enabled = true;
}

private void OnMouseOver()
{
    displayInfo = true;
}

private void OnMouseExit()
{
    displayInfo = false;
}

}

Grow Animation
  • 163
  • 4
  • 13
  • What is the value of `text` when you debug it for house2? And what does it mean for it to "fail" for the second and default cases; you get an exception, it doesn't hit it, etc? – Blake Thingstad Feb 02 '18 at 17:28
  • `OnPointerEnter` and `OnPointerExit` are used for this. Please remove the `OnGUI` function from your code. That's for the old Unity's UI system. – Programmer Feb 02 '18 at 17:34
  • By failing I mean the text doesn't appear for house2. – Grow Animation Feb 02 '18 at 17:41

0 Answers0