collision problem

Hello I have this script

var object : Transform;

function OnTriggerEnter (collision : Collider) {
	if(collision.object){
		//Do Stuff
	}
}

what am I doing wrong?

Hey,

It depends what you are trying to do…
If you are trying to see if a certain object is coming into contacting (colliding) with another, try something like this script:

function OnCollisionEnter(hit: Collision){
	if(hit.gameObject.tag == "tagOfObjectToCollideWith"){
		//Now Do Stuff
	}
}

attach this to any object. Then if you want to check if it’s colliding with a certain object, then tag that object and put that tag where it says: tagOfObjectToCollideWith.

You can also use GameObject.Find instead of using tags if you like.
Just replace hit.gamObect.tag == "tagOfObjectToColllideWith" with hit.GameObject.Find("gameObjectInYourScene")

Here are some links you can check out!:

GameObject.Find Scripting Reference: http://unity3d.com/support/documentation/ScriptReference/GameObject.Find.html

OnCollisionEnter Scripting Reference: http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.OnCollisionEnter.html

Hope this helps you out, and if you need more help or if I didn’t quite answer your question, then feel free to comment back! :smiley:

-Grady