How do I make it so a death animation will play when I hit an enemy?
Hi guys, I am working on a 2d infinite runner game, and I don't know how to play a death animation when I hit an enemy. I added a 2D box collider and a 2D rigidbody, but I don't know how to make it so that when the player is running and hits an enemy, a death animation plays? Here is my script:
using System;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace UnityStandardAssets._2D
{
public class Restarter : MonoBehaviour
{
void OnCollisionEnter2D(Collision2D coll)
{
if (coll.gameObject.tag == "Enemy")
GetComponent<Animation>().Play("RedGianDEATHTOALL");
{
if (coll.gameObject.tag == "Enemy")
coll.gameObject.SendMessage("ApplyDamage", 10);
}
}
}
}
Any ideas?
A.K.A, Ignore the title of my script. I just edited a script that came with Unity3D
Comment
Your answer
Follow this Question
Related Questions
Why is my player dying when defeating an enemy? 1 Answer
How to stop Enemy when dead 2 Answers
play a death animation when a the gameobject is destroyed But Please I want it JS Script 0 Answers
how to restart without time,.timescale effecting it 2 Answers
How to create transitions in the animator without creating a disaster? (Layers?) 0 Answers