Hello. I’m making good progress on my latest game. I use tagging for destroying other gameobjects.
However, when touching an enemy, it often destroys another instance of the object, than the one the Player is touching.
This is the player touching the enemy
else if (other.CompareTag("Enemy_Carnivore"))
{
if (isLethal)
{
Instantiate(scorePlus, new Vector3(transform.position.x, transform.position.y + 1.5f, transform.position.z), Quaternion.identity);
FindObjectOfType<EnemyCarnivore>().death();
And this is the code for destroying the enemy:
public void death()
{
Destroy(gameObject, 0.7f);
Anim.SetTrigger("Destruction");
AudioSource.PlayClipAtPoint(damage, Camera.main.transform.position, damageSoundVolume);
FindObjectOfType<GameSession>().destructionScore();
}
If i put destroy() on the player part, it destroys the distinct enemy, however, the death animation of the enemy is never triggered.
Is there a way to destroy the distinct instance of the enemy where the animation is also part of it?