Search Unity

KeyDown -> Animate once and pause?

Discussion in 'Editor & General Support' started by Gibbonuk, Jan 24, 2014.

  1. Gibbonuk

    Gibbonuk

    Joined:
    Dec 10, 2013
    Posts:
    175
    Hi, I have a model with a single animtion of 10 frames. What im trying to do is, whilst a key is held down (which does other stuff) it playes the animation until the end and then stop and stays on the last frame and then when i let go fo the key it reverse the animation back to the start?

    Now I thought I had cracked it when I found clampForver but I noticed the longer its "clampedforever" the long it takes to reverse the animation? Is time still going on after its got to the last frame? I dont quite understand?

    This is my current code... (c#)

    Code (csharp):
    1. if (Input.GetKey ("b")) {
    2.                 if (!myObj.animation.IsPlaying("ani1")){
    3.                         myObj.animation["ani1"].speed = 1;
    4.                         myObj.animation["ani1"].wrapMode = WrapMode.ClampForever;
    5.                         myObj.animation.Play ("ani1", PlayMode.StopAll);
    6.                         }
    7.                 }
    8.  
    9.         if (Input.GetKeyUp ("b")){     
    10.                 myObj.animation["ani1"].speed = -1;
    11.                 myObj.animation["ani1"].wrapMode = WrapMode.ClampForever;
    12.                 myObj.animation.Play("ani1",PlayMode.StopAll);
    13.                        
    14.                 }
    Hope you can advise.
    Thanks
    Andy