I am trying to show a GUI Label when mouse overs over an object and the label hides when mouse cursor is removed from object.
Can anyone please let me know why am i getting the error ?
using UnityEngine;
using System.Collections;
public class label_diet : MonoBehaviour {
public showGUI boolean = false;
void OnMouseOver()
{
showGUI = true;
}
void OnMouseExit()
{
showGUI = false;
}
void OnGUI()
{
if (showGUI)
{
GUI.Label(new Rect(10, 10, 100, 20), "You are selecting Diet coke");
}
}
}
Change the line that reads
public showGUI boolean = false;
To
public bool showGUI = false; //for C#
public var showGUI = false; //for JS, but you're using C#
That should work fine; if not, check that the script is attached either to a UI Object or an object with a collider component.