Input.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"代表回车或返回

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;
		}
	}
}
最后修改:2011年3月11日 Friday 18:47

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。