Reputation: 103
I'm trying to delay my scene loading just a bit to let my button sound play through before the new scene gets loaded, but I seem to be having errors, which is weird considering the exact same code worked for my other button. The Debug below does not get called. Thank you!
public class DeathScene : MonoBehaviour {
public void PlayAgain()
{
Invoke("Restart", 0.25f);
}
void Restart()
{
Debug.Log("restart");
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
}
Upvotes: 1
Views: 341
Reputation: 1622
Time.scale
is not zero.gameObject
is not destoryed.IsInvoking
is true.If all no problem but Invoke
still not work,it maybe bug of Invoke
,use StartCoroutine
.
Upvotes: 3
Reputation: 1286
Invoke
doesn't work for a destroyed GameObject
. I suppose your GameObject
gets destroyed before PlayAgain
is fired. Check it via OnDestroy
void OnDestroy () {
Debug.Log("Oops");
}
Upvotes: 1