K
K
kapitansen2015-03-30 11:55:39
JavaScript
kapitansen, 2015-03-30 11:55:39

How to get text from InputField in new UI out of the box?

There is an InputField object named NameField. I'm trying to do this:

var NameField : GameObject; // в редакторе привязал к нему InputField 
function Game_Start () {
    var NameField_input =NameField.GetComponent("InputField");
    var Name = NameField.text;
    Debug.Log(Name);
  }

The console writes that "text is not a member of UnityEngine.GameObject". value instead of text doesn't work either.
I feel that I forgot to include some module or library.
There are many examples on the net, but they are either in C# or in the old GUI.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
kapitansen, 2015-03-30
@kapitansen

I answer myself. Here is the code that worked:

var NameField : UnityEngine.UI.InputField; // в редакторе привязал к нему InputField 
      function Game_Start () {
     		var Name = NameField.text;
     		Debug.Log(Name);
  }

There was a typo in the previous code, I did not use the NameField_input that I got from the NameField. Thanks Daniil Basmanov .

D
Daniil Basmanov, 2015-03-30
@BasmanovDaniil

You have a typo, you are not using the NameField_input that you got from the NameField. In general, it's better to start learning C #, it's not difficult.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question