Collision With Character Controller

Hey, Im new to unity but find it very interesting ^^

Ive bin struggeling with a problem for several hours now, and I can cleary see that i need some help with it.

I have a turret firing balls into my world, and when the balls hit my character(First Person Character Controller) i want the game to stop (gameover)

But i dont know how to do this.

Can anyone link me a tutorial or a script that could do this, thank you very much in advance ;)

Okay this seems to work..

function OnCollisionEnter (other : Collision) 
{ 
    if (other.gameObject.name == "FirstPersonController") { 
       print("Game Over");
   } 
}

Get the distance between the fire ball (Prefab?) and the player using Vector3.Distance(FIREBALL,PLAYER);

Then do an if statement to check if the fireball hit the player... If so, then start a new scene, where it shows they lost, or if you want to keep the background, tweak a pause game script... Search for one of those!

=)

I was thinking about: Can i somehow put a tag on the character controller and tell the ball script that when it collides with something that has that tag the game will pause or shift to another scene? ;) RoflJOE 58 secs ago

I know this is old but I’ve had the same problem for a little while now and have come up with a very useful solution. I don’t know how efficient it is, but it does work.

In the OnControllerColliderHit function you want to send a message to the object you’ve collided with that contains the name of the function you want to call and the ID of the object you hit, just to be safe.

/* In the script attached to the character */
function OnControllerColliderHit (hit : ControllerColliderHit) { 
     hit.gameObject.SendMessage("RecieveMessage", hit.gameObject.GetInstanceID());
}

/* In the script attached to the object */
function Recievemessage (id) {
     if(id == gameObject.GetInstanceID()) {
          print id;
     }
}

So essentially the CharacterController hits the object then tells the object “hey, I hit you.” Seems to work in my game. Hope this helps.