- Home /
Wait until animation is finished
Hi everyone. I am trying to fade out and in between scenes but the scene always loads before the fading is finished. So I am trying to find a way to execute code after the animation is finished. I am an amateur coder so I just want a simple solution if possible.
Here is the code:
public void LoadScene (string sceneName) { blackScreen.SetActive (true); blackScreen.GetComponent ().Play (); Wait (); print ("10 seconds passed");
}
IEnumerator Wait() {
yield return new WaitForSeconds (10);
}
Answer by ibobtouch · Mar 02, 2019 at 04:55 PM
Mmmm... is it because you call your function directly with "Wait()" and not by "StartCoroutine(Wait());" ?
And by the way, if you have a function like this
instruction 1
instruction 2
StartCoroutine(fn());
instruction 3
Everything will be executed at the same time, so you need to put what you want to be executed after the Wait, at the end of the coroutine.
Your answer
![](https://koobas.hobune.stream/wayback/20220612123856im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Pause script until animation is finished. 1 Answer
Ienumerator wait for event 0 Answers
WaitUntil and WaitWhile don't work 1 Answer
Animation play when player collides/hits an GameObject 0 Answers
Loop animation with a wait in between 3 Answers