Object destroys on collision script

So I want my “Gayballs” to disappear when they hit something and I’ve made some code here and it doesn’t give me any errors but doesn’t seem to be working.There’s more code where the Gayball prefab is instantiated. And I put this script on my Gayball prefab. Could anyone see what’s wrong here? Thanks in advance :slight_smile:

var GayballPrefab : Transform;
var wall : String = "Cube";

function OnCollisionEnter(collision : Collision)
{
	if (collision.gameObject.GayballPrefab == wall)
	{
		Destroy(GayballPrefab);
	}
}

function Update () 
{

No surprise - this is completely wrong! Forget about the GayballPrefab: you can identify the hit object by name or tag - gameObject.GayballPrefab doesn’t exist!

function OnCollisionEnter(collision : Collision) { 
    if (collision.gameObject.name == "Wall"){ // if the hit object's name is Wall...
        Destroy(collision.gameObject); // destroy it
    }
}

function OnCollisionEnter(collision : Collision) {
if (collision.gameObject.name == “Wall”){ // if the hit object’s name is Wall…
Destroy(gameObject); // destroy it
}
}

otherwise it would destroy the wall :stuck_out_tongue:

PS: it would be better if u create a tag , just change collision.gameObject.name to collision.gameObject.tag