Make a GameObject destroy a different GameObject when player touches it

How do i make a GameObject destroy a different GameObject when touches a Player

Hi !
Here is the solution :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MyScript : MonoBehaviour
  public Transform OpenObject;
  [SerializeField] private GameObject myObject;
  // Start is called before the first frame update
  void Start()
  // Update is called once per frame
  void Update()
  private void OnTriggerEnter2D(Collider2D other)
      if (other.gameObject.CompareTag("Trap"))


In Unity go where’s the script to drag and drop the object you want to delete on “myObject” (Red Arrow on the picture).
exemple unity destroy

You can also use public GameObject myObject; instead of [SerializeField] private GameObject myObject;

Is the object i pick have to be a trigger or tagged trap?

thank you alot! i got it working!

can you change the public GameObject myObject; to a list

Sure !
Just replace it with this line :

public List<GameObject> myObject = new List<GameObject>();

In unity enter how many objects you want to have :
exemple unity destroy 2
And drag and drop your objects as previously.