How to play an animation on collision
So i have a topdown space shooter like game and i need to play a death animation whenever it collides with an asteroid. I scripted the collision but i dont know how to make the animation play. Please help im lost:/
Attach some scripts. You can execute: animator.Play("animatio_name")
Please, follow the Unity tutorials for basic question such as yours
https://unity3d.com/fr/learn/tutorials/topics/animation/animator-scripting?playlist=17099
Answer by L-Chee · Oct 23, 2018 at 02:05 PM
Remenber:
Add an Animator to your gameobject ,then add the script also the animation you drag in to script should be controled by your your Animator.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class animation : MonoBehaviour {
public AnimationClip youranimation;
void OnCollisionEnter()
{
GetComponent<Animation>().Play();
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612131125im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Is there a way to limit animation on collision? 1 Answer
How do I Trigger my elevator to go up and then return back down? 1 Answer
Unable to stop animation upon collision (2d, animation, rigidbody) 0 Answers
Why is my ragdoll messing up my animation? 0 Answers
how should i put the colliders? 1 Answer