- Home /
The variable has not been assigned error ?
I want to display the name of object along with some other text like, when i mouse over a coke can, a text saying " You are selecting coke" should be displayed. I tried it hard coding, by giving it label and then mouseover and it worked.
But i want a code in which the object name should be assigned during run time like, if mouse over overs a coke can it should say "You are selcting coke" and when its diet coke it should say " You are selecting diet coke"
I tried writing a code, it says "The variable textObject of label_diet has not been assigned" can anyone say why the error ?
using UnityEngine;
using System.Collections;
public class label_diet : MonoBehaviour {
public GUIText textObject;
public bool showGUI;
void OnMouseOver()
{
textObject.text = gameObject.name;
showGUI = true;
}
void OnMouseExit()
{
showGUI = false;
}
void OnGUI()
{
if (showGUI)
{
GUI.Label(new Rect(Input.mousePosition.x,Input.mousePosition.y,100f,100f), "You are selecting Diet coke"+textObject.text);
}
}
}
Comment