I have a player prefab that I would like to destroy after it touches the collider of an enemy. The name of the enemy prefab is Enemy, and the name of the player prefab is Player (bland, I know…). I have this bit for the script that should destroy the character
using UnityEngine;
using System.Collections;
public class PlayerTrigger : MonoBehaviour
{
void OnTriggerEnter2D(Collider2D col)
{
if (col.gameObject.tag == "Enemy") {
Destroy (gameObject);
}
}
}
But when I run the game, nothing happens after the Player touches the Enemy. Am I doing something wrong?
How can I fix it? I'm still learning how objects interact in Unity.
– ChoiJ0527