How do I get the input from inputfield ?
Iv’e tried the
Changestring method
OnSubmit Method
and
InputField myInput = GameObject.Find("InputField").GetComponent<InputField> ();
string input = myInput.text;
I’ve tried lots of versions I found on the internet… None work for me, any help ?
If you look at the InputField, you can see there is actually a child Text object which holds the text. You need to reference that:
InputField myInput = GameObject.Find("InputField").GetComponent<InputField> ();
string input = myInput.textComponent.text;
I’m getting : A field initializer cannot reference the non static field, method or property
I think something else must be wrong. myInput.text and myInput.textComponent.text are both working fine for me.
Try adding this test script to your input field:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
publicclassTest : MonoBehaviour {
private InputField _input;
void Start ()
{
_input = gameObject.GetComponent<InputField>();
}
void Update ()
{
Debug.Log(_input.text);
Debug.Log(_input.textComponent.text);
}
}
1 Like
Thanks mate, it works now