The following script is attached to a GameObject with many children (Unity 4.6 GIU text objects). I want to turn them on (child welcomeText in this case) or off based on a public static int nextNum which I already have working. I’d like to stick to using the public static int nextNum as I want to sequence animation events aswell as the text objects. The program runs but then pauses with the following error, plus a number of objects in the scene disappear.
using UnityEngine;
using System.Collections;
public class welcomeTextControl : MonoBehaviour
{
void Start ()
{
GameObject.Find("welcomeText").SetActive(false);
}
void Update ()
{
if (SetButInc.nextNum == 1)
{
GameObject.Find("welcomeText").SetActive(true);
}
else
{
GameObject.Find("welcomeText").SetActive(false);
}
}
}
Error: NullReferenceException: Object reference not set to an instance of an object
welcomeTextControl.Update () (at Assets/Scripts/welcomeTextControl.cs:20)