zoukankan      html  css  js  c++  java
  • 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/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

  • 相关阅读:
    C 扩展库
    访问nginx时验证密码
    关于redis闪退的案例
    查看进程的准确启动时间
    Ansible随笔8
    Ansible-随笔-7
    运维基本工作
    随笔-ansible-6
    随笔-ansible-5
    随笔-ansible-4
  • 原文地址:https://www.cnblogs.com/PEPE/p/3597739.html
Copyright © 2011-2022 走看看