In my scene I have one script for all triggers. When player come inside one of the triggers, I want to enable some object (smoke), and then disabje object, which contain current script.
To access smoke I use Find and when I try to enable it, I got error: “Object reference not set to an instance of an object”
May be it because Find need more time to find it? I can’t use public GameObject, because I use this script in many places in my game.
void OnTriggerEnter()
{
if(nameOfObjectWithTrigger == "RedButtonTrigger")
{
//..
}
else if(nameOfObjectWithTrigger == "WaterTrigger")
{
//..
}
else if (nameOfObjectWithTrigger == "MiddleCube")
{
GameObject smoke = GameObject.Find("SmokeDoor");
smoke.SetActive(true); // Error
gameObject.SetActive(false);
}
}