I am new to unity and want to get a value from a input text field. I found this question Get text from Input field in Unity3D with C#, but when I execute it the same error always appear: NullReferenceExcpetion : Object reference not set to an instance of an object. It seems like a stupid mistake and I tried everything but can't seem to fix it. My code:
void Start () {
var input = gameObject.GetComponent<InputField>();
input.onEndEdit.AddListener(SubmitName);
}
private void SubmitName(string arg0)
{
Debug.Log(arg0);
}
I tried putting InputField input
; before the start function and erasing var
but still no luck.
If anyone can help me with this problem it would be much appreciated.
Pictures of where my scripts are attached at the moment.