Hey all,
I’m making a 2D game where if you jump on the Enemies head (which is where a empty object with a box collider 2D that is set to trigger is on it) it will destroy the gameObject, it works really well with one enemy but the second there is two it will delete in Numerical order.
i have two scripts, one for the enemy and detecting whether or not it’s health is low enough to destroy and one for detecting the if the Player has collieded with the enemies head collider.
PlayerMove.cs
` void OnTriggerEnter2D(Collider2D col)
{
if (col.gameObject.name == "InflictDamage")
{
GameObject.FindGameObjectWithTag("Enemy").GetComponent<EnemyScript>().EnemyHealth -= DamageInflict;
}
}
}`
EnemyScript.cs
`void Update()
{
transform.Translate(Time.deltaTime * -1, 0, 0);
if (EnemyHealth <= 1)
{
GameObject.Find("Player").GetComponent<PlayerMove>().DeathSound.Play();
Destroy(gameObject);
}
}`