- Home /
Animation End/Scene Change
Hello there, I have a quick question. How might I create a script in which when a certain animation ends, it loads a specific scene? This would be quiet helpful, thank you.
I have found a script on here, but I've no idea how to apply it. Here is the script:
animation.Play(animation.clip.name);
yield WaitForSeconds (animation.clip.length + 2);
Application.LoadLevel ("Credits");
Answer by aldonaletto · Oct 21, 2013 at 02:49 AM
This code shows the basic idea: start an animation and use its length (duration) to generate a delay after which the new level is loaded. Let's suppose that you want to start the "Death" animation and load the scene after that:
function PlayDeathAndLoadCredits(){
animation.CrossFade("Death"); // smoothly start the Death animation
yield WaitForSeconds(animation["Death"].length); // wait time enough
Application.LoadLevel("Credits"); // animation finished: load Credits
}
Attach this code to the object script and call PlayDeathAndLoadCredits() when you want to do the magic.
Your answer

Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Animation problems 1 Answer
How would you make a shapeshifting mechanic in a game? 1 Answer
Why does my climb stairs animation not play? 1 Answer
How to click a 3d object in unity3d? 3 Answers