i want to open and close a door with same button...
i use PingPong but when i press key to open it.. its starts repeating the animation...
and if i use once it do it just one time and after pressing againg it again open the door
i just want to use same open animation in reverse...with same key
what do to. ??
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");
}
}
but how to do this with the same key to open it and close it?
– anon81813364Look for Input.GetKeyUp("k") and have a boolean called 'open' that is toggled, somethng like the above
– DaveAYou could of course also look for GetKeyDown ;)
– DaveAok ..but still animation is not working in reverse...
– anon81813364use a negative speed to play the animation backwards, you shouldn't use pingpong for this. animationState.speed = -1.0f; //<- like this
– anon95292375