Please help with a simple collision.

I have tried every script out there on the internet. None of them work. All I am trying to do is have a collision between a cylinder and first person controller. Pretty much, when the Player hits the cylinder, the Log says something. That isn’t what it is supposed to do, but all I want to do is get this to work. Please help.

My code:

function OnCollisionEnter(theCollision : Collision){
	if(theCollision.gameObject.tag == "Enemy"){
		Debug.Log("fjeoijfoiejfoiejf");
	}
}

This is any and all code I have for the entire thing.

Screenshot of unity (red text was edited in)

Character Controllers are weird. They don’t use the standard callbacks.

If you want to know if the charter controller has collided with an object you need to use an OnControllerColliderHit callback

I just don’t use them, I build my own controllers using real Unity physics.

Hmmm… Didn’t work for me.
My code was:

function OnControllerColliderHit(hit : ControllerColliderHit){
	if(hit.gameObject.tag == "Enemy"){
		Debug.Log("feee");
	}
}

Also, I have the script attached to my character. Is this right?

Your script seems fine. What you are missing is the “Enemy”-tag on the cylinder.

At the screenshot your “Enemy1” is labelled as “Undefined” under tag.

Make a new one called “Enemy” if it doesn’t exist already and then remember to add the tag to the cylinder.

That should make it work.^^