Changing text through a cursor hover trigger
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: https://imgur.com/a/Aco64
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;
}
void Update()
{
Display();
}
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;
}
}
Your answer
Follow this Question
Related Questions
Going NUTS- Tring to return a list from another script 3 Answers
[SOLVED] NullReferenceException in a script that calls another object's script variable 1 Answer
Does Polybrush use GPU Instancing for detail meshes? 1 Answer
How to make conversation UI similar to Pillars of Eternity or Planescape:Torment 0 Answers
How to display text with delay (No GUI code in script) 1 Answer