How can I make the Player be destroyed when I touch the end of the camera?

hi guys i want my player to be destroyed when i hit the camera … i used the following scrpits but it did not work

first on the camera I put a collider

and I entered this code

private void OnTriggerEnter2D (Collider2D other)
    {
        if (other.gameObject.CompareTag ("Player"))
        {
            Destroy (player);
        }
    }

but it did not work

so I inserted it into the player

private void OnTriggerEnter2D (Collider2D other)
    {
        if (other.gameObject.CompareTag ("MainCamera"))
        {
            Destroy (gameObject);
        }
    }

and still nothing

please help me!

There are a lot of places where this could be going wrong but you can try this…

First, put a Box Collider2D on the Main Camera. Edit that collider so that it is the full size of the viewable area (click the Edit Collider button on the component and drag the green box the the full size). Then check the Is Trigger box.

Be sure your player has a RigidBody 2D and a Box Collider 2D attached.

Put the following script on your Main Camera…

using UnityEngine;

public class DestroyPlayer : MonoBehaviour
{
    private void OnTriggerExit2D(Collider2D other)
    {
        if (other.tag == "Player")
        {
            Destroy(other.gameObject);
        }
    }
}