I can’t quite figure out why the GUItextbox won’t change values like I believe it should (upon pressing space). I eventually want in-game events to change the text displayed in the GUItextbox and this is my broken down version of it. It tells me that the text box.myText is never being assigned and the “hello” is not becoming “You pressed space!”.
public class textbox : MonoBehaviour {
GUIText myText;
// Use this for initialization
void Start()
{
GameObject guiText = new GameObject("SomeGUIText");
Instantiate(guiText);
GUIText myText = guiText.AddComponent<GUIText>();
myText.transform.position = new Vector3(0.02f,0.1f,0f);
myText.guiText.text = "Hello";
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown (KeyCode.Space)) {
myText.guiText.text = "You pressed space!";
}
}
}
`