简体   繁体   English

将InputField值存储在变量中-UNITY

[英]Store InputField value in variable - UNITY

I am creating a new game all by myself. 我自己创建了一个新游戏。 But I have a problem. 但是我有一个问题。 I have an InputField and I need its value... I've seen many answers, but inputFieldName.text doesn't work, and I am using UI, declared the InputFIeld and it still doesn't work! 我有一个InputField,我需要它的值...我看到了很多答案,但是inputFieldName.text不起作用,并且我正在使用UI,声明了InputFIeld,但它仍然不起作用! HELP! 救命!

You have to set the value object on game screen for use DragAndDrop into the script to define public property. 您必须在游戏屏幕上设置值对象,以便在脚本中使用DragAndDrop来定义公共属性。 Then you must select text component on awake or start event in script. 然后,您必须在脚本中选择处于唤醒状态或启动事件的文本组件。

 public GameObject gameTextObject; // Set this object on gameScreen for use DragAndDrop

        void Start(){

          if( gameTextObject == null)
            {
              // if you set gameTextObject  on gameScreen this object not be null 
              gameTextObject = GameObject.Find("InputObjectName");
            }

         // GetObjectText
         string gObjectTextValue = gameTextObject.Text;

          // SetObjectText
          gameTextObject.GetCOmponent<Text>().text = "Any Text";       
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM