I have a script attached to GameObject Options and i want to target the component Text and change it’s content, but everything I tried returned Null.
I tried:
public Button button;
public Text txtButton;
changeText() {
button = GameObject.FindWithTag("Button");
txtButton = button.GetComponent<Text>();
txtButton.text = "Something";
}
It always return null (NullReferenceException) when i try do target the Text component inside the Button, but the button itself returns ok.
And here’s the hierarchy, considering that the script is attached to Options GameObject (Inside a Canvas):
