您的位置:首页 > 移动开发 > Unity3D

Unity3D笔记 英保通五 鼠标事件与GUI系统双击检测

2014-03-13 07:52 513 查看
一、如何使用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("双击了鼠标");
}
}
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: