Unity 3D enter Number in Inputfield and get an event

点点圈 提交于 2019-12-11 17:55:35

问题


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

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.

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


回答1:


Assuming you declared inputfield in your script:

public InputField inputField1;

Try to activate inputfield after showing it:

inputField1.ActivateInputField();

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

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


来源:https://stackoverflow.com/questions/54131840/unity-3d-enter-number-in-inputfield-and-get-an-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!