本文介绍了Unity 3D在Inputfield中输入Number并获取一个事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的游戏中是一个Gamobject.如果我通过按E进行交互,则会显示输入字段和提交"按钮.

In my game is a Gamobject. If I interact with it by pressing E the inputfield and the Submit button show up.

如何在inputField中输入内容?我想通过按ESC键来获取鼠标,但这并不是一种很好的方法.

How can I enter something into the inputField? I figured out to get the mouse by pressing ESC but that aint a beautiful way to do it.

我已经看到了将inputFields的值另存为字符串的方法.整数的工作方式是否相同?

I have seen ways to save the value of inputFields as Strings. does it work the same way with integers?

推荐答案

假设您在脚本中声明了inputfield:

Assuming you declared inputfield in your script:

public InputField inputField1;

尝试在显示输入字段后激活它:

Try to activate inputfield after showing it:

inputField1.ActivateInputField();

要将inputField的值保存为整数,您需要将其值转换为int:

To save the value of inputField as integer you need to convert its value to int:

var value = int.Parse(inputField1.text);

这篇关于Unity 3D在Inputfield中输入Number并获取一个事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 17:29