Fist of all I am an absolute begginer I have a 2d platformer in which I have a Mario like squishing mechanic when I jump on an enemy it dies.So I have created a box with a trigger box colider2d on to the enemy which is the child object to it and if I jump on the box first it should destroy the enemy and if touch it instead it should kill me, but instead when I jump on the box it destroyes the enemy after which it kills me as well…which means that the enemy script is running as well
here is the box trigger script
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player")
{
Destroy(transform.parent.gameObject);
Destroy(gameObject);
}
}
and here is the enemy script
private bool fall;
public GameObject Player;
public Transform spawnPoint;
public bool stomp;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player")
{
Application.LoadLevel(Application.loadedLevel);
}
}
Thank you very much !