I need a little help with Collision

Okay guys, so I am learning C# as I go so I apologize for any stupid questions.

What I am trying to do right now is have an object (as well as the LinkedSpriteManager sprite drawn over it) be destroyed whenever it collides with any of four boundary cubes. I don’t even need a specific object to be destroyed, just anything that comes in contact with the walls.

I have tried using ControllerColliderHit.gameObject as so:

using UnityEngine;
using System.Collections;

public class Walls : MonoBehaviour
{
	void OnCollisionEnter() {

		Destroy(ControllerColliderHit.gameObject);
		
	}
}

(attached to the walls that I want to destroy anything that collides with them)

but I receive “UnityEngine.ControllerColliderHit.gameObject: An object reference is required for the nonstatic field, method or property”.

This is the same error that is generated when I try to use any Collider functions such as Collision.gameObject.

Does anyone have any insight? Perhaps another way to do things? I feel I am missing something terribly obvious.

you are passed in an collider in the collision enter. You need to use that reference to work with.
you are workign with a class reference, not an object reference, thus working with “nothing related to the current collision”

The correct code would be something alike:

using UnityEngine;
using System.Collections;

public class Walls : MonoBehaviour
{
   void OnCollisionEnter(collisionInfo : Collision) {

      Destroy(collisionInfo .gameObject);
      
   }
}

Thanks dreamora, I spent all night fiddling with that and it worked fine in JS but I wanted something that worked in C, and I couldn’t for the life of me figure it out. I ended up just giving up and setting transform.position parameters that would destroy my objects.

Now I just need to figure out how to destroy the sprite before the object and I’ll be golden.