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

  • 相关阅读:
    python中使用scikit-learn和pandas决策树进行iris鸢尾花数据分类建模和交叉验证
    CNN+ Auto-Encoder 实现无监督Sentence Embedding ( 基于Tensorflow)
    R语言数据可视化分析案例:探索BRFSS数据
    1.微信小程序里如何设置当地时间?
    63.1拓展之纯 CSS 创作一个摇摇晃晃的 loader
    63.(原65)纯 CSS 创作一个摇摇晃晃的 loader
    6.HTML+CSS制作一双眼睛
    62.纯 CSS 创作一只蒸锅(感觉不好看呀)
    61.纯 CSS 创作一只咖啡壶(这个不好看)
    60.纯 CSS 创作一块乐高积木
  • 原文地址:https://www.cnblogs.com/zhangweia/p/3649456.html
Copyright © 2011-2022 走看看