- Home /
C# WaitForSeconds Question.
Am i trying to make it too simple? :P 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);
}
}
}
Answer by tanoshimi · Jan 11, 2015 at 08:47 AM
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 http://docs.unity3d.com/ScriptReference/GameObject.SetActive.html).
Do you get any errors in the console log?
Answer by HarrisonJH · Jan 11, 2015 at 09:32 AM
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.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
How to "Restart level after 2 seconds " 1 Answer
Function with itself called inside it. (JavaScript) 2 Answers
How to import the object from server to unity 2 Answers
Can someone help me fix my Javascript for Flickering Light? 6 Answers