- Home /
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) { if(other.gameObject.CompareTag("Player")){ other.gameObject.SendMessage("OnScore", null); destroy = true;
} }
Here's the score gui's script:
var score : int = 0; function OnScore(){ score+=1; } function OnGUI () { GUI.Label (Rect (10, 10, 100, 20), "SCORE: " + score);
}
Does anyone know what's wrong here?
The error reposrt is saying that OnScore has no receiver..
I am not able to run Unity where I am... is there a version of Send$$anonymous$$essage that takes just a method name? I cant remember. It might be getting confused thinking it should be looking for a method with one argument (that happens to be set to null in your case). Try that or add a bogus float to the method. I'm pretty sure reflection is used to look up the method name.
Answer by · Oct 10, 2010 at 12:53 AM
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.
Answer by Bampf · Oct 09, 2010 at 08:25 PM
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.
Your answer
Follow this Question
Related Questions
Player Character Health 2 Answers
Collision script 1 Answer
pushing object 2 Answers
Help with player death on collision! 2 Answers