Stop specific animation from Animator

Viewed 60

I am animating different gameobjects while using the same animator:

public void Balances()
 {
     if (Monitors[0].activeSelf)
     {
         MonitorAnimations[0].Play("Monitor1-Animation", -1, 0f);
         KeyAnimation.Play("Monitor1-KeyAnimation", -1, 0f);
     } else if (Monitors[1].activeSelf)
     {
         MonitorAnimations[1].Play("Monitor2-Animation", -1, 0f);
         KeyAnimation.Play("Monitor2-Key-Animation", -1, 0f);
     } else if (Monitors[2].activeSelf)
     {
         MonitorAnimations[2].Play("Monitor3-Animation", -1, 0f);
         KeyAnimation.Play("Monitor3-Key-Animation", -1, 0f);
     }
 }

The usecase is: the user can switch between different monitors and each monitor has an own KeyAnimation. What I would like to achive is to stop for example "Monitor1-KeyAnimation" when Monitors[0] get's disabled.

I only found:

myAnimation.gameObject.GetComponent<Animator>().enabled = false;

which disables the animator completely, so it also stops the other animations from playing.

Has anyone an idea how I can achieve the right behaviour?

0 Answers
Related