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("双击了鼠标");
        }
    }
}

 

 

 

posted @ 2014-03-13 07:52  PEPE YU  阅读(553)  评论(0编辑  收藏  举报