Simple Kill/Destroy player on TriggerCollision?

Been looking everywhere and tried over 10 scripts… Not sure why it ain’t working?
I just want this Trigger Box Collider to destroy the Player if he enter it…
Or preferably, play a “Death” animation before being destroyed.
Any simple way to do this? Current script is this but not working:

public class DeathBoxCollider : MonoBehaviour
{

    // Use this for initialization
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {

    }

    void OnCollisionEnter(Collision otherObj)
    {
        if (otherObj.gameObject.tag == "Player")
        {
            Destroy(gameObject, .5f);
        }
    }

If you are using a Trigger, you will want to use the following:

void OnTriggerEnter2D(Collider2D otherObj)
{
        if (otherObj.gameObject.tag == "Player")
        {
            Destroy(gameObject, .5f);
        }
}

Kinf of working… When I enter the box collider I destroy the box collider… So I want it the opsoite way…
Like, destroy “player” instead… Any idea how? Thanks tough!

void OnTriggerEnter2D(Collider2D otherObj)
{
        if (otherObj.tag == "Player")
        {
            Destroy(otherObj.gameObject, .5f);
        }
}

or if you want to play the death animation, set it up in the player’s animator with a trigger connected to the death animation, probably “Death”, then

void OnTriggerEnter2D(Collider2D otherObj)
{
    if (otherObj.tag == "Player")
    {
        Animator animator = otherObj.gameObject.GetComponent<Animator>();
        animator.SetTrigger("Death");
        Destroy(otherObj.gameObject, length of death animation);
    }
}

Its working :slight_smile:
Thank you soo much!