C# WaitForSeconds Question.

Am i trying to make it too simple? :stuck_out_tongue: So when i build it, it say’s it’s correct but absolutely nothing happens.
All it’s supposed to do is after 5 seconds screen 1 disappears so that Screen2 behind it shows.

Here it is


using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour 
{
	IEnumerator Start() 
	{
		yield return new WaitForSeconds(5);
		{
			GameObject.Find("Screens/Screen1").SetActive(false);
		}
	}
}

Is “Screens” active in the hierarchy? A child object will not be active unless its parent is also active, so calling SetActive on Screens/Screen1 may have no effect (described at Unity - Scripting API: GameObject.SetActive).

Do you get any errors in the console log?

Seems like GameObject.Find("Screens/Screen1") didn’t find the instance, but you said no console errors.

 using UnityEngine;
 using System.Collections;
 
 public class ExampleClass : MonoBehaviour 
 {
     public GameObject screen1;

     IEnumerator Start() 
     {
         yield return new WaitForSeconds(5);
         screen1.SetActive(false);
     }
 }

And drag and drop the screen1 object in the inspector. See if this works.