0

I'm using C# script to change the text of 9 buttons and a label by clicking one button. I can change the text of the clicked button by using this code:

public void BeenClicked()
{
    this.GetComponentInChildren < Text >().Text= "Hi";
}

as long as the script is associated with the button (and not in a script holder). But I can't access the rest of the objects to change their values. Any help is highly appreciated!

Alex Myers
  • 6,196
  • 7
  • 23
  • 39
Reza
  • 21
  • 4
  • Make the 9 public Button variables or use array to hold them then use and register to onClick event. Use your GetComponentInChildren when there is a click to get the text attached to each one. Example 2 in the duplicate answer shows how to register to multiple Buttons event. – Programmer Jan 10 '18 at 02:24
  • the easiest thing to do is to add a public reference to all the text objects you'd like to change in your script, assign them appropriately via the editor, and then simply change what you need to change within "BeenClicked()". – oxrock Jan 10 '18 at 02:26

0 Answers0