- Home /
why wont this SendMessage work
Im trying to send message to score to -5 when ever I instantiate an object, i've managed to get everything else fine but now it's late and i'm derping it.
var spentAmount : int = -5;
if(GameObject.Find("__GameMaster").GetComponent(Score).score >= 5){
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit)) {
Instantiate (particle, hit.point, transform.rotation);
GameObject.Find("__GameMaster").GetComponent(Score).score)SendMessage("SetScore"), spentAmount);
I know the error is that last line but for the life of me i cant get it to work... this is how i did my others via on trigger
function OnTriggerEnter(other: Collider){
if(other.gameObject.tag == "Enemy"){
//Debug.Log("Enemy");
guiRef.SendMessage("SetStability", stabilityAmount);
Destroy(other.gameObject);
Destroy(other.transform.parent.gameObject);
}
but this one is attached to the object and it works fine need to figure out the top one
you have an incredible mess of ( ) braces on line 8. first fix that !
Not sure what line 8 in your first code snippet is supposed to do, but it has an uneven number of opening and closing parenthesis. If you are trying to call the SetScore() function on the gameObject with the name "__Game$$anonymous$$aster", then your code should look like this:
GameObject.Find("__Game$$anonymous$$aster").Send$$anonymous$$essage("SetScore", spentAmount);
Answer by brunopava · May 10, 2013 at 06:59 PM
// this line is wrong
GameObject.Find("__GameMaster").GetComponent(Score).score)SendMessage("SetScore"), spentAmount);
// not sure why are you getting the score, but this should work.
GameObject.Find("__GameMaster").SendMessage("SetScore", spentAmount);
Your answer
Follow this Question
Related Questions
Best way to access variables of script from granchild of another object, into a different script? 1 Answer
Problems with cloning, aka double trouble. 0 Answers
Instantiate an enemy, best way to initialize behavior variables 1 Answer
Null Reference Exception on instantiated objects script. 1 Answer
Endless 3D plane repetition animated by script is not moving 0 Answers