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

  • 相关阅读:
    js添加获取删除cookie
    华为Scan Kit二维码扫描
    Android中使用抖动动画吸引来用户注意-属性动画
    material_dialogs 动画弹框
    flutter 通过widget自定义toast,提示信息
    flutter 通过用户信息配置路由拦截 shared_preferences
    fluterr shared_preferences 存储用户信息 MissingPluginException(No implementation found for method getAll on channel
    Android Scroller及实际使用
    Antd Tree简单使用
    iOS开发--runtime常用API
  • 原文地址:https://www.cnblogs.com/zhangweia/p/3649456.html
Copyright © 2011-2022 走看看