Quantcast
Channel: Questions in topic: "die"
Viewing all articles
Browse latest Browse all 115

How do I disable enemy ai the script after enemy ai dies

$
0
0
I need to disable the script when the enemy ai die.Because what is going on is the enemy ai is follow the player after and before it dies . Here is the enemy ai attack, idle , and move script : using UnityEngine; using System.Collections; public class Enemyai : MonoBehaviour { public Transform player; static Animator anim; void Start () { anim = GetComponent (); } public void Stop(){ anim.SetBool("isWalking", false); anim.SetBool("isAttack", false); anim.SetBool("isIdle", true); this.enabled = false; //Or if you want to destroy the AI script completely //Destroy(this) } void Update () { if (Vector3.Distance(player.position, this.transform.position) < 20) { Vector3 direction = player.position - this.transform.position; direction.y = 0; Player.gameObject.activeSelf; this.transform.rotation = Quaternion.Slerp (this.transform.rotation,Quaternion.LookRotation(direction), 0.1f); anim.SetBool("isIdle",false); if(direction.magnitude > 2.6 ) { this.transform.Translate(0,0,0.09f); anim.SetBool("isMoving",true); anim.SetBool("isAttack",false); } else { anim.SetBool("isAttack",true); anim.SetBool("isMoving",false); } } else { anim.SetBool("isIdle",true); anim.SetBool("isMoving",false); anim.SetBool("isAttack",false); } } } Enemy ai has to deactivate first and then the die animation play on the health script : private void DieLocal(Vector3 position, Vector3 force) { // Notify those interested. EventHandler.ExecuteEvent(m_GameObject, "OnDeath"); EventHandler.ExecuteEvent(m_GameObject, "OnDeathDetails", force, position); // Spawn any objects on death, such as an explosion if the object is an explosive barrell. for (int i = 0; i < m_SpawnedObjectsOnDeath.Length; ++i) { ObjectPool.Instantiate(m_SpawnedObjectsOnDeath[i], transform.position, transform.rotation); } // Destroy any objects on death. The objects will be placed back in the object pool if they were created within it otherwise the object will be destroyed. for (int i = 0; i < m_DestroyedObjectsOnDeath.Length; ++i) { if (ObjectPool.SpawnedWithPool(m_DestroyedObjectsOnDeath[i])) { ObjectPool.Destroy(m_DestroyedObjectsOnDeath[i]); } else { Object.Destroy(m_DestroyedObjectsOnDeath[i]); } } // Deactivate the object if requested. if (m_DeactivateOnDeath) { Scheduler.Schedule(m_DeactivateOnDeathDelay, Deactivate); GetComponent().Play(); anim.SetTrigger("isDead"); } }

Viewing all articles
Browse latest Browse all 115

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>