Unity判断双击


using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class doubleKick : MonoBehaviour
{
    float Scale = .5f;
    private double lastKickTime; // 上一次鼠标抬起的时间(用来处理双击)
    void Awark()
    {
        lastKickTime = Time.realtimeSinceStartup;
    }
    void Start()
    {
    }
    void Update()
    {
        if (Input.GetMouseButtonUp(0))
        {
            CheckCreateCube();
        }
    }
    void CheckCreateCube()
    {
        RaycastHit hit;
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        if (Physics.Raycast(ray,out hit) && hit.transform == transform)
        {
            if (Time.realtimeSinceStartup - lastKickTime < 0.5)//检测上次点击的时间和当前时间差 在一定范围内认为是双击
            {
                print("双击");
            }

            lastKickTime = Time.realtimeSinceStartup;//重新设置上次点击的时间
        }
    }
}

你可能感兴趣的:(Unity判断双击)