Unity3D圣典3.3版本-中文版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
Input.inputString 输入字符串
# [Input](Input.html).inputString 输入字符串 static var *inputString* : string *Description* 描述 Returns the keyboard input entered this frame (Read Only). 返回在这一帧的键盘输入(只读) Only ASCII characters are contained in the inputString. inputString 中只包含 ASCII 码中的字符。 The string can contain two special characters which should be handled: Character "\b" represents backspace. Character "\n" represents return or enter. 这个字符串中可以包含两个需要处理的特殊字符:字符"\b"代表退格。字符"\n"代表回车或返回 * [C#](#) * [JavaScript](#) ``` using UnityEngine; using System.Collections; public class example : MonoBehaviour { void Update() { foreach (char c in Input.inputString) { if (c == "\b"[0]) if (guiText.text.Length != 0) guiText.text = guiText.text.Substring(0, guiText.text.Length - 1); else if (c == "\n"[0] || c == "\r"[0]) print("User entered his name: " + guiText.text); else guiText.text += c; } } } ``` ``` // Shows how to read typing input from the keyboard // (eg. the user entering his name). // You need to attach this script to a GUIText object. // 演示怎样读取键盘输入的字符 //(例如用户输入他的名字) //你需要将此脚本附加于一个GUIText对象 function Update () { for (var c : char in Input.inputString) { // Backspace - Remove the last character //退格 - 移除最后一个字符 if (c == "\b"[0]) { if (guiText.text.Length != 0) guiText.text = guiText.text.Substring(0, guiText.text.Length - 1); } // End of entry //完成进入(登录,登入) else if (c == "\n"[0] || c == "\r"[0]) {// "\n" 用于 Mac, "\r" 用于 windows. print ("User entered his name: " + guiText.text); } // Normal text input - just append to the end //普通文本输入 - 只是添加到最后 else { guiText.text += c; } } } ```
da
2022年5月23日 14:02
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码