Okay, so I’m kind of new to coding in Unity, and I keep getting a null reference exception error in one of my programs. I’m working with EZGUI, and I’m basically trying to change the text on one of my labels based on which button is clicked on the menu. Any help would be greatly appreciated; I’m at a loss here.
Here’s the code:
SpriteText operatorLabel;
MainMenuManager operatorData;
// Use this for initialization
void Start ()
{
operatorLabel = GameObject.Find ("Label Operator").GetComponent<SpriteText>();
//and here's the error:
operatorData = GameObject.Find ("Main Menu Manager").GetComponent<MainMenuManager>();
SetOperator(operatorData.newOperator);
}
void SetOperator(string newOperator)
{
operatorLabel.Text = newOperator;
}
Where does the null reference say it is occurring? Should give you script name and line number...
– vbbartlettIt's line 11 on this one
– emjm109921Most likely is a failure of GameObject.Find() to find the object. Verify that the spelling and capitalization is identical between the code above and the named game object. Evan an extra space at the end of the name will cause this method to fail. Also make sure you are not mixing up names and tags.
– robertbu