How to pause a script while an animation is being played.

An Example for rolling dice, I got a random number using the Random.Range(1, 7) function. I play the corresponding random number animation of the dice. Here is my question. I need to pause the execution of the script while the animation is being played and then continue with the script once the animation stops. Here is a sample script.

        var DiceAnim = new Array("Dice1","Dice2","Dice3","Dice4","Dice5","Dice6")
        var RandomDiceNumber = Random.Range(1, 7);
        GameObject.Find("Dice").animation.Play(DiceAnim[RandomDiceNumber]);
            // The next part of the script has to play once the animation stops. How can I do it.
        PlayerCoinMovement();

Try using yield.

For your specific problem, you can either use `yield WaitForSeconds(x);`, where x is the length of the animation in seconds. Or you could create a new component to play the animation, and send a callback to the script when the animation is done.

Thanks for you reply. :)

You could do something like:

if(!animation.IsPlaying("animationName")){
   //Code that you only want to run when 
   //animationName is not playing goes here
}

script for play and pause animation