animation event keeps repeating

Hi , I have an animation which for other scripting reasons I should check the “play automatically” and it will play when i play my project . though I want a 5 seconds delay at the start of my animation . I put an event at my fist frame of my animation and wrote a function for it like this:

var myAnim : Animation;

function myYield(){
    yield WaitForSeconds(5);

but it seems that the function keeps repeating! is there anything wrong in this code? I’ll be appreciated if anyone can help me with this .

Think of an animation as being like a “tape” of a movie. At any point in time, the tape is wound to a certain position. What you would like to do is to play the movie from the current position. If we look at the Animation.Stop method we see that it is documented as “Stopping an animation also rewinds it to the start”. It is the last bit that is causing you trouble. This not only stops the animation but rewinds the “tape”. So when you start playing again, it starts from the very beginning.

What you want to do is pause the animation. Look at the animation entry found here:

This will give you access to the AnimationState. A property in this object is called “enabled”. Setting this to false will suspend the animation. Resetting it to true will restart the animation.