一、如何使用GUI事件来检测鼠标是否按下的事件:
获取当前事件:var e:Event=Event.current;
using UnityEngine;
using System.Collections; public class BtnEvent : MonoBehaviour
{ // Use this for initialization
void Start()
{ } // Update is called once per frame
void Update()
{ } void OnGUI()
{
Event e = Event.current; if (e.button == && e.isMouse)
{
Debug.Log("鼠标左键被按下");
}
else if (e.button == && e.isMouse)
{
print("鼠标右键被按下");
}
else if (e.button == && e.isMouse)
{
print("鼠标中键被按下");
}
else if (e.button > && e.isMouse)
{
print("你按了什么鼠标键 我不知道");
}
}
}
二、如何检测鼠标双击?
using UnityEngine;
using System.Collections; public class BtnEvent : MonoBehaviour
{
void OnGUI()
{
Event e = Event.current; if (e.isMouse&&e.clickCount==)
{
Debug.Log("双击了鼠标");
}
}
}