So i have what should be a fully working enemy behaviour script with movement , object destruction on death , and death animation on death, triggered by a trigger in the animator
This screenshot has the player and 3 zombies that are the enemy , when they get shot , they play their death animation and then after 5 seconds their gameobject is destroyed.
But what is happening is that i shoot the first zombie on the left , and the death animation plays on the last zombie on the right , but it disables the left zombies box collider.So in conclusion when the first zombie gets hit the death animation plays on the other zombie , but it still disables the first zombies box collider and sets its gravity to 0(even though sometimes they still fall off the map)
this is the code that handles the colision:
Collision function:
private void OnCollisionEnter2D(Collision2D col)
{
//Deals With Collisions Between enemy
// and bullet,or enemy and player
if (col.gameObject.tag == “Bullet”)
{
EnemyAnimator.SetTrigger("Death");
DestroyObject(col.gameObject);
isDead = true;
}
if (col.gameObject.tag == "Player")
{
EnemyAnimator.SetTrigger("Atack");
StartCoroutine(MyMethod2());
CharMovement.Vida--;
}
}
function to delay enemy gameobject destruction :
IEnumerator MyMethod()
{
//Delays code when
//enemy dies
EnemyRigidbody.gravityScale = 0;
EnemyBoxCollider.enabled = false;
yield return new WaitForSeconds(3);
Destroy(this.gameObject);
}
void Update()
{
if (isDead == true)
{
StartCoroutine(MyMethod());
}
else
{
EnemyMov();
OnCollisionEnter2D(EnemyColl);
}
if (atack == true)
{
OnCollisionEnter2D(EnemyColl);
}
}
Thanks in advance and if the code i pasted here is too hard to figure out without the rest of the script let me know , i will upload the full script on txt format