Trouble sending message...

I'm trying to send a message from a coin prefab to a score gui to add 1 to the score everytime my player collides with a coin. Here's the coin script:

function OnTriggerEnter(other : Collider) {
other.gameObject.SendMessage("OnScore", null);
destroy = true;


Here's the score gui's script:

var score : int = 0;
function OnScore(){
function OnGUI () {
GUI.Label (Rect (10, 10, 100, 20), "SCORE: " + score);


Does anyone know what's wrong here?

SendMessage "calls the method named methodName on every MonoBehaviour in this game object."

OnScore() won't be found unless it's on the Player object, and by the sounds of things it isn't.

The idea looks sound.

  • Make sure your player object has a collider and is assigned the tag "Player".
  • Make sure the coin collider is set to be a Trigger.

Use the debugger or put a Debug.Log line at the top of the OnTrigger function to make sure it is getting called. If it is, then the test for player tag is failing. If it isn't, then the problem is with getting the trigger to fire.