For those searching for a solution to use PingPong only once, without repeating, I have seperate solution post here:
[Ping Pong Only Once][1]
In terms of playing an animation just forward, then just backwards on a key stroke, which seems to be the actual intent of the query in this posting, here is a complete C# implementation derived from DaveA's clever answer above.
bool isOpen = false;
void Update() {
if (Input.GetKeyDown(KeyCode.K))
{
isOpen = !isOpen;
if (isOpen )
{
animation["open"].time = 0;
animation["open"].speed = 1;
}
else
{
animation["open"].time = animation["open"].length; // Start at the end...
animation["open"].speed = -1; // ...and run backwards!
}
animation.Play("open");
}
}
[1]: http://answers.unity3d.com/questions/291732/play-animation-forward-than-immediately-backwards.html#answer-693278
↧