This script is attached to the player:
using UnityEngine;
using System.Collections;
public class RestartLevel : MonoBehaviour {
void OnTriggerEnter2D(Collider2D OtherObject) {
if(OtherObject.gameObject.CompareTag("Enemy")) {
Debug.Log ("Collision");
Destroy (OtherObject);
}
}
}
There is also a “Box Collider 2D” attached to the player and it is also used as a trigger.
To every enemy in the game I also attached a Box Collider 2D, whenever the player touches an enemy the player is suppose to be destroyed but nothing is happening, it goes through them.