S
S
StynuBlizz2019-11-21 15:41:52
Unity
StynuBlizz, 2019-11-21 15:41:52

Is there an easy way in unity to start the animation of an object once?

The problem is, I need to run the animation once (the user made a mistake with the input and I need to shake the object as if telling him about the error), but this animation can be run many times. In order for me to implement this, I had to create an animation, an animator, create a default empty state in the animator, create a trigger, and set the transition from this default state to animation by trigger and back, and set the trigger in the code. In principle, it’s not so difficult, but there are a lot of similar (not in appearance, but because they are one-time) animations and I don’t want to do this for each element. Is there something similar to the animation component that you just throw an animation on, and then run it from the code by name?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wezwery, 2020-06-22
@Wezwery

public Animator animator;

void Trigger(){
      animator.Play("name");
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question