- Home /
Animation in unity
Can i animate an object in unity and have that animation played when triggered by a trigger. Also do animations have to repeat or can they just play through the animation once.
Answer by theLucre · Dec 09, 2014 at 07:20 AM
If you have a reference to the Animator component in your script, you can trigger animations using the SetTrigger, SetBool, SetInt, or SetFloat methods. If you are checking for an OnTriggerEnter from another object, you can always send a message to the collider.gameObject to fire some kind of reaction, which can include your Animator triggers.
As for looping, I tend to have a second state which is an idle state which the Animator will revert to at the end of an animation that should be played once. The single loop animation has a transition to the Idle state with a condition of exit time = 1.00.
Answer by alok-kr-029 · Dec 09, 2014 at 09:20 AM
void OnTriggerEnter(Collider other) { gameobject.animation.Play("animation_name"); }
Your answer
![](https://koobas.hobune.stream/wayback/20220613173605im_/https://answers.unity.com/themes/thub/images/avi.jpg)