• Unity 代码检测单击,双击,拖放


    今天小伙伴问我如何自己写一段代码检测 单击 双击 和 拖放.于是就写了这段代码O(∩_∩)O~

    image

    代码如下:

    using UnityEngine;
    using System.Collections;
    
    public class Test2 : MonoBehaviour {
    
        public float oneTime;           //检测双击的有效时间
        private int downCount;          //判断是单击还是双击
        private bool currentCheck;      //当前正在检测
        private bool isTuoDong;         //是否拖动
        private bool startTuoDong;      //开始拖动
        void Update () {
    
    
            if(Input.GetKeyDown(KeyCode.A))
            {
                downCount++;
                isTuoDong = true;
                if (currentCheck == false) 
                {
                    StartCoroutine(CheckDown());
                }
            }
    
            if (Input.GetKeyUp(KeyCode.A)) 
            {
                isTuoDong = false;
                startTuoDong = false;
            }
    
            if (startTuoDong) 
            {
                Debug.Log("正在拖动");   
            }
        }
    
        IEnumerator CheckDown() 
        {
            currentCheck = true;
            yield return new WaitForSeconds(oneTime);
    
            if (isTuoDong) 
            {
                Debug.Log("拖动");
                startTuoDong = true;
    
            }else if (downCount >= 2)         //说明是双击
            {
                Debug.Log("双击");
            }
            else if (downCount == 1)    //单击
            {
                Debug.Log("单击");
            }
    
            downCount = 0;
            currentCheck = false;
    
        }
    
    }
    如果你感兴趣,你可以把你妹妹介绍给我
  • 相关阅读:
    oracle 监听 添加ip
    重装系统windows
    oracle user pwd
    mybatis
    sum行列合计
    IIS8.5 运行WCF
    exp自动备份在bat中不执行
    oem 重建
    yum install oracle-validated
    MSHflexgrid控件删除选中行
  • 原文地址:https://www.cnblogs.com/plateFace/p/4394830.html
Copyright © 2020-2023  润新知