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!

Hi there,

There is not a lot of information in your question, but i will suppose that your game is 2D, and that the “IsTrigger” component of the Camera’s collider is set to true.

With these statements, the most probable mistake is that you don’t have a Tag named “Player”. My guess is that you are trying to compare it to the GameObjects name, instead of Tag.

So you have two options here, create a Tag, and set the Player’s tag.

The second option is to compare directly the gameobjects name:

other.gameObject.name.Equals("Player")

Hope it helps, if this is not the case, we will need more information about your collider, names, tags, etc…