There are plenty of answers to this question, but non seem to help my case.
This is what I have done so far and why I need to get the length, and maybe there is even a different way of doing what I’m trying to do.
I have two animations that run simultaneously and they can also be ran backwards.
I have a plane, and the plane has a cockpit and landing gears.
The landing can be down, and the cockpit animation can be ran while the landing gear animation is on as well.
I was able to do this by creating each animation with a different layer. The layers are set to be additive.
I added two float parameters and added each one to me a multiplier.
I created a script that attaches to the game object to start the animations.
public class AnimController : MonoBehaviour {
public Animator aries;
void Start () {
aries = GetComponent<Animator>();
}
void Update () {
if (Input.GetKeyDown("1"))
{
aries.SetFloat("CockpitDirection", 1);
aries.Play("Cockpit");
}
if (Input.GetKeyDown("2"))
{
aries.SetFloat("CockpitDirection", -1);
aries.Play("Cockpit");
}
}
}
When I hit “1”, the cockpit animation starts and opens the cockpit, and when I hit “2” the animation reverses and starts to close.
The problem I found is that the timer for the animation keeps running after it has ended, so if I let one minute go by after the cockpit is open, and then I hit “2” to close the cockpit, the animation will will take one minute for it to start closing.
My thoughts were if i stop the animation, or pause the animation when the animation is over, When I press “2” to close the cockpit, it will not take X amount of time for the cockpit to close.
Maybe I’m thinking of this wrong, and maybe there is another way of doing this?
If you guys could help, that would be amazing. Thank you for taking the time to read this long post and trying to figure this out with me.