Hi. I am trying to change the text on a button from the text entered on an InputField in another scene. Here’s the code I am using, calling createAccountName() when a button in the same scene with InputField is clicked:
public class CreateNewAccount : MonoBehaviour {
public InputField enterAccountName;
public GameObject aObject;
public Button aButton;
public void createAccountName () {
aObject = GameObject.Find ("User2"); //The button name is User2
aButton = aObject.GetComponent<Button> ();
aButton.GetComponentInChildren<Text>().text = enterAccountName.textComponent.text;
}
}
I get a Exception “Object reference not set to an instance of an object”. What am I doing wrong? Thank you.