0

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.

enter image description here

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 :)

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.