Search Unity

playing whole animation clip before stopping

Discussion in 'Scripting' started by mlager8, Jan 24, 2011.

  1. mlager8

    mlager8

    Joined:
    Jan 24, 2011
    Posts:
    7
    I looked around the forum but can not seem to find the answer to this, I'm sure it's cake for you guys, but I am a complete amateur and have never written a line of code before so hopefully I can enlist your help. All I'm trying to do is have a 1 second animation play when I hit the "E" button and stop upon release. This is what I have:
    function Update () {
    if (Input.GetKey(KeyCode.E))
    animation.Play("Fab_Spray");
    //yield WaitForSeconds(2);
    //yield WaitForSeconds(animation.clip.length);

    if (Input.GetKeyUp(KeyCode.E))
    animation.Stop("Fab_Spray");
    //animation.Rewind("Fab_Spray");

    }

    Right now this plays the animation when I hold down "E" but if I release, it stops in the middle of the clip. I tried the wait for seconds command but instead it froze my animation and nothing happens. I am lost on what it going on or how to get what I want, if anyone could offer assistance it would be greatly appreciated.