**I have this script and I'm trying to make that when the enemy is dead he is replace by a ragdoll and not by a animation. Help me guys please!!!**
**The script:**
using UnityEngine;
using System.Collections;
public class EnemyController : MonoBehaviour {
NavMeshAgent nav;
Transform player;
Animator controller;
float health;
GameManagement game;
CapsuleCollider capsuleCollider;
Animator anim;
bool isDead = false;
// Use this for initialization
void Awake () {
nav = GetComponent ();
player = GameObject.FindGameObjectWithTag ("Player").transform;
controller = GetComponentInParent ();
game = FindObjectOfType ();
health = 20 + (1.25F * game.round);
capsuleCollider = GetComponent ();
anim = GetComponent ();
}
// Update is called once per frame
void Update () {
if (!isDead) {
nav.SetDestination (player.position);
controller.SetFloat ("Speed", Mathf.Abs (nav.velocity.x) + Mathf.Abs (nav.velocity.z));
}
}
void ApplyDamage(float damage)
{
//print (damage);
health -= damage;
if (health <= 0)
Death ();
}
void Death ()
{
// The enemy is dead.
isDead = true;
nav.Stop ();
// Turn the collider into a trigger so shots can pass trough it.
capsuleCollider.isTrigger = true;
anim.SetTrigger ("isDead");
//GameManagement.score += 10;
//GameManagement.monet += 10;
// Change the audio clip of the audio source to the deat clip and play it.
//enemyAudio.clip = deatClip;
//enemyAudio.Play ();
Destroy (gameObject, 0f);
}
}
↧