Event.button 鼠标按钮
var button : int
Description描述
Which mouse button was pressed.
哪一个鼠标按钮被按下。
0 means left mouse button, 1 means right mouse button, 2 means middle mouse button. Used in EventType.MouseDown, EventType.MouseUp events.
0表示鼠标左键,1表示鼠标右键,2表示鼠标中键。在EventType.MouseDown,EventType.MouseUp事件中使用。
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
void OnGUI() {
Event e = Event.current;
if (e.button == 0 && e.isMouse)
Debug.Log("Left Click");
else
if (e.button == 1)
Debug.Log("Right Click");
else
if (e.button == 2)
Debug.Log("Middle Click");
else
if (e.button > 2)
Debug.Log("Another button in the mouse clicked");
}
}
// Detect which mouse button is currently pressed and print it.
//检测当前按下的鼠标按钮并打印
function OnGUI() {
var e : Event = Event.current;
if(e.button == 0 && e.isMouse){
Debug.Log("Left Click");
} else if(e.button == 1) {
Debug.Log("Right Click");
} else if (e.button == 2) {
Debug.Log("Middle Click");
} else if (e.button > 2) {
Debug.Log("Another button in the mouse clicked");
}
}
最后修改:2010年12月31日 Friday 23:11