Unity3D笔记 英保通五 鼠标事件与GUI系统双击检测
一、如何使用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 == 0 && e.isMouse) { Debug.Log("鼠标左键被按下"); } else if (e.button == 1 && e.isMouse) { print("鼠标右键被按下"); } else if (e.button == 2 && e.isMouse) { print("鼠标中键被按下"); } else if (e.button >2 && e.isMouse) { print("你按了什么鼠标键 我不知道"); } } }
二、如何检测鼠标双击?
using UnityEngine; using System.Collections; public class BtnEvent : MonoBehaviour { void OnGUI() { Event e = Event.current; if (e.isMouse&&e.clickCount==2) { Debug.Log("双击了鼠标"); } } }
作者:PEPE
出处:http://pepe.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。