输入文字时让人物停止不动的代码
var playName = "None";
static var currentControl ;
function Update() {
if( currentControl)
return;//当有任何输入框被点击时屏蔽之后的内容
if (Input.GetKey(KeyCode.UpArrow)||Input.GetKey(KeyCode.W)){
transform.Translate(Vector3.forward*0.5);
}
if (Input.GetKey(KeyCode.DownArrow)||Input.GetKey(KeyCode.S)){
transform.Translate(Vector3.forward*-0.5);
}
if (Input.GetKey(KeyCode.LeftArrow)||Input.GetKey(KeyCode.A)){
transform.Rotate(Vector3.down *2);
}
if (Input.GetKey(KeyCode.RightArrow)||Input.GetKey(KeyCode.D)){
transform.Rotate(Vector3.up *2);
}
}
function OnGUI(){
playName = GUI.TextField(Rect(10,10,100,20),playName);
//当鼠标按在除输入框的 任意位置时
if( Input.GetMouseButtonDown( 0 ) && GUIUtility.hotControl == 0 )
GUIUtility.keyboardControl = 0;
currentControl = GUIUtility.keyboardControl;
}
ps:不管输入框在那个Scrpit中,只要在想屏蔽的地方的OnGUI加上面的代码就行,
if( Input.GetMouseButtonDown( 0 ) && GUIUtility.hotControl == 0 )
GUIUtility.keyboardControl = 0;不用重复加入。