- Home /
Question by
zmigmbh · Oct 04, 2021 at 02:34 PM ·
animationgameobjectanimatoractivestop animations
Stop specific animation from Animator
Hello Unity community,
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.
Comment
Your answer
Follow this Question
Related Questions
Best Way - Animation - Multiple GameObjects. 0 Answers
How to play the second animation in the animator controller other than the default animation ? 2 Answers
changing a game object with another 0 Answers
Animator - Do After Playing Animation 1 Answer
Object's sprite and collider are not at same position as transform 1 Answer