- Home /
Question by
dahc2332 · Apr 09, 2012 at 12:15 AM ·
animations
Wait to Start Script
How do I delay a script to wait until an animation is completed before it is enabled?
Comment
Answer by TehWut · Apr 09, 2012 at 12:48 AM
you could try something like this:
animation.Play(animation.clip.name);
// Wait for the animation to have finished
yield WaitForSeconds (animation.clip.length);
*pseudoCode*
var script: OtherScript;
script.DoThis();
//
instead of a function, just set that to enable / disable whatever you had in mind.
Answer by GuyTidhar · Apr 10, 2012 at 12:48 PM
void CallToAnimate()
{
StartCoroutine("AnimateAndWait");
}
IEnumerator AnimateAndWait()
{
animation.Play(animation.clip.name);
// Now that the animation is running - wait for that long before continuing
yield return new WaitForSeconds(animation.clip.length);
// Time's up - call to what ever procedure you wish
YourFunction();
}
void YourFunction()
{
//What ever you want to do after animation is done
}
Set the animation variable to yours and function names as you please. Make sure you use StartCoroutine("FunctionName"), so the yield and wait are actually wroking.
The Problem is I'm trying to apply it to the Look Around script that is provided by Unity. But I can't get it to work.
Your answer
Follow this Question
Related Questions
Simple Character Animations 2 Answers
Unity Jet Wing Animations! Help! 1 Answer
Declaring animations on a script in the editor 1 Answer
How do i make an animation play on key press? 3 Answers
Play animation from script in Unity 4.3 0 Answers