I wanted to make a simple prototype of a 2D character swinging a sword, so I attached the player tag to the parent and attached the sword as a child with a Weapon tag. I want the player to die when being touched by an enemy but the enemy to die when its being touched by the sword.
I have attached the respawning script to the player which detects when the enemy touches it, however it seems to also be triggered when the enemy is touching the sword child. I have tried to tell it to only trigger when interacting with this.tag Player but it didn't help.
Do I have to separate the sword completely or is something that could help me out here?
Here is the code I tried
if (other.tag == "Enemy" && this.tag == "Player")
{
foreach (GameObject enemy in enemies)
{
enemy.GetComponent<EnemyAI>().EnemyRespawn();
}
Respawn();
}
Thank you for the help!