Reputation: 2147
I've been stuck on this for a little while. I want to call an onClick action for a button from another script.
I.E. see the below capture. I want to call that onClick from another script.
I tried this.transform.GetChild(0).SendMessage("onClick", number);
but I keep getting SendMessage onClick has no receiver! error.
Any idea what I am missing?
Thank you in advance :)
Upvotes: 0
Views: 4076
Reputation: 3625
Are you sure that you are sending the message to right GameObject
? In your case the Main Camera
, not the button. Your code works in my unity 4.6.2. You can print the name of the GameObject
with this:
Debug.Log(this.transform.GetChild(0).gameObject.name);
If the GameObject
is the right, and the message doesn't still work you can always get the component and call the function old fashion way without messages:
this.transform.GetChild(0).gameObject.GetComponent<ShopBtns>().onClick(number);
Upvotes: 1