C# coroutine not waiting on waitForSeconds?
Ok this should work but I dont know if its stopping on yield return or just hasn't finished. Im not getting debug 3 and my level is not loading the next scene. am i doing something wrong? Using unity 5.4.0
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class SplashScreen : MonoBehaviour {
public float waitTimer;
public int levelIndex;
public KeyCode skipKey;
void Start() {
Debug.Log("1");
StartCoroutine(SplashWait());
}
void Update() {
if (Input.GetKey(skipKey)) {
StopAllCoroutines();
SceneManager.LoadScene(levelIndex);
}
}
IEnumerator SplashWait() {
Debug.Log("2");
yield return new WaitForSeconds(waitTimer);
Debug.Log("3");
SceneManager.LoadScene(levelIndex);
}
}
Answer by JACKO4590 · Sep 11, 2016 at 08:18 AM
Hahaha found it. Time scale was set to 0 for some f-ed up reason, i was about to rip my hair out.
Answer by doublemax · Sep 11, 2016 at 07:49 AM
I tested the script and it works as expected. Did you set a reasonable value for waitTimer ?
Yeah mate. I set it to 3 and even set it to 1 just for testing. Putting null in s$$anonymous$$d of wait works but not what I want. If it works on yours then there must be something on my end?
I don't see anything that could go wrong here. Try creating a new empty project, add one object and attach the script to it and see what happens.
What happens in of outcomment the LoadScrene call in SplashWait? Do you get the "3"?
Thank you for you help, it was time scale set to 0 that was stopping coroutine running
New project and it worked.
The only object i have in my main scene is the game jam menu. Other then that Realistic FPS prefab is the other asset i have imported that re writes system settings like tags, layers ect