zoukankan      html  css  js  c++  java
  • unity3d 事件

    1. 键盘事件

    public class keyboard : MonoBehaviour {
    
        private int pressTime = 0;
        // Use this for initialization
        void Start () {
        
        }
        
        // Update is called once per frame
        void Update () {
        
            if(Input.GetKeyDown(KeyCode.A))
            {
                Debug.Log("keyDown A");
            }
    
            if (Input.GetKeyUp (KeyCode.A)) {
                Debug.Log("KeyUp A");
                pressTime = 0;
            }
    
            if (Input.GetKey (KeyCode.W)) {
                Debug.Log("LongKeyPress Timer:" + pressTime);
                pressTime++;
            }
    
            if (Input.anyKey) {
                Debug.Log("any key LongPress");
            }
    
            if (Input.anyKeyDown) {
                Debug.Log("any keydown");
            }
        }
    }
     
    组合键思路:
          一旦玩家按下了某键后,便开启时间计时,记录一段时间内玩家的按键信息,然后与正确的比较,超时或者按错一个失败。
     
    2. 鼠标按键事件
    public class mouse : MonoBehaviour {
    
        // Use this for initialization
        void Start () {
        
        }
        
        // Update is called once per frame
        void Update () {
        
            if (Input.GetMouseButtonDown (0)) {
                Debug.Log("press down mouse left");
            }
    
            if (Input.GetMouseButtonDown (1)) {
                Debug.Log("press down mouse right");
            }
    
            if (Input.GetMouseButtonDown (2)) {
                Debug.Log("press down mouse middle");
            }
    
            if (Input.GetMouseButtonUp (0)) {
                Debug.Log("press up mouse left");
            }
    
            if (Input.GetMouseButton (0)) {
                //Input.mousePosition -->三维坐标
                Debug.Log("press long down left" + Input.mousePosition);        
            }
        }
    }

    3. 自定义事件

        自定义按键以组合的方式出现,可以设置多个按键同时影响。 Edit—>Project Setting –> input

  • 相关阅读:
    将Web项目War包部署到Tomcat服务器基本步骤(完整版)
    性能实战分析-环境搭建(一)
    SQL Server Profiler追踪数据库死锁
    性能测试的各种监控工具大全
    python学习
    Linux常见面试题一
    Linux下用于查看系统当前登录用户信息的4种方法
    HDU 1394 Minimum Inversion Number(线段树求逆序对)
    SGU 180 Inversions(离散化 + 线段树求逆序对)
    Codeforces Round #FF (Div. 2) C. DZY Loves Sequences
  • 原文地址:https://www.cnblogs.com/zhangweia/p/3649456.html
Copyright © 2011-2022 走看看