- Home /
Waitforseconds not working?
Hello,
This may be a common question but my waitforseconds doesn't seem to be working. What I want to do is after you click on a component, it takes 1-2 seconds before a panel shows up. This is what I have so far:
using UnityEngine; using System.Collections;
public class OnColliding : MonoBehaviour {
public GameObject Panel;
public float Wait = 5;
void Start () {
Panel.SetActive(false);
}
void OnMouseDown() {
StartCoroutine (PanelWait ());
Panel.SetActive (true);
Time.timeScale = 0F;
}
IEnumerator PanelWait ()
{
yield return new WaitForSeconds (Wait);
}
}
But it's not working, the panel shows up immediately after clicking. Help please? I'm still a beginner.
Answer by Jessespike · Feb 12, 2016 at 09:06 PM
void OnMouseDown() {
StartCoroutine (PanelWait ());
}
IEnumerator PanelWait ()
{
yield return new WaitForSeconds (Wait);
Panel.SetActive (true);
}
Answer by alankemp · Feb 12, 2016 at 02:25 PM
You are setting Time.timeScale to 0, which means no time is actually passing inside WaitForSeconds.
See this answer for an alternate approach:
http://answers.unity3d.com/questions/301868/yield-waitforseconds-outside-of-timescale.html
To get the panel to show up after the wait, move the call to Panel.SetActive (true); inside the coroutine, after the WaitForSeconds.
Thanks for answering. How can I do that in scripting though? Sorry, I know very little about it...
Your answer

Follow this Question
Related Questions
SpeedBoost won't reset : Problem with either WaitForSeconds or Coroutine (Solved) 2 Answers
What's stopping 'WaitForSeconds' from working? 1 Answer
Is there a way to make WaitForSeconds ignore time.timescale? 1 Answer
GameObject moving back and forth, moves slightly further left each time. 1 Answer
WaitForSeconds not working in IEnumerator function using MoveNext 1 Answer