Question by
Vid-Maddness · Aug 13, 2017 at 10:41 PM ·
c#animationanimatorridgidbody
Death animation for enemy
I have a script for my gun to shoot and kill enemies with raycasts but i can't figure out how to play an animation for the character from an animator after you destroy the charactor
using UnityEngine;
public class Gun : MonoBehaviour {
public float damage = 10f;
public float range = 100f;
public Camera fpsCam;
public ParticleSystem muzzleFlash;
public GameObject impactEffect;
// Update is called once per frame
void Update () {
if (Input.GetButtonDown ("Fire1"))
{
Shoot ();
}
}
void Shoot ()
{
muzzleFlash.Play();
RaycastHit hit;
if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
{
Debug.Log(hit.transform.name);
Target target = hit.transform.GetComponent<Target>();
if (target != null)
{
target.TakeDamage(damage);
}
GameObject impactGO = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal));
Destroy(impactGO, 2f);
}
}
}
Please i really need help
Comment