Destroy an object just bumping into another

Sorry for the mistakes of English, I am Brazilian and beginner in Unity

Hello
I wish someone would help me create a script like so:

When Colliding with a wall, an object from another room is destroyed.

I tried some script in this regard and not found.
I tried to create a script with this function

function OnCollisionEnter(collision: Collision)

{

Destroy(MyObject)

}

Help me please T_T

The basic idea is correct, but maybe OnCollisionEnter isn’t the right event: OnCollision events are reported only when a rigidbody hits a collider. If the object that collides with the wall is a CharacterController (like the First Person Controller prefab), this won’t work because OnCollision events aren’t generated - you should use OnControllerColliderHit instead. But in this case there’s another issue: this event is only sent to the character script, and your code seems to be attached to the wall. A possible solution would be to make the character script call a function in the wall script. Let’s suppose that the wall script is saved as WallScript.js, and looks like this:

var myObject: GameObject; // drag here the object to be destroyed

function DestroyMyObject(){
  Destroy(myObject);
}

You could use the OnControllerColliderHit event in the character script to call DestroyMyObject in the wall script:

function OnControllerColliderHit(hit ControllerColliderHit){
  // try to get WallScript from the object you've collided with:
  var wallScript: WallScript = hit.transform.GetComponent(WallScript);
  // if it has a WallScript, call DestroyMyObject:
  if (wallScript) wallScript.DestroyMyObject();
}