【Unity实用小方法】鼠标双击的判断

using UnityEngine;
using System.Collections;

public class DoubleClick : MonoBehaviour {

    //计时器,在一定的时间内双击有效
    private float time = 0f; 
    //计数器
    private int count = 0;
 	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
        if (Input.GetMouseButtonDown(0))
        {
            
            count++;
             //当第一次点击鼠标,启动计时器
            if (count == 1)
            {
                time = Time.time;

            } 
            //当第二次点击鼠标,且时间间隔满足要求时双击鼠标
            if(2 == count && Time.time - time <= 0.5f) 
            {
                print("双击了鼠标");
                count = 0;
            }
            if(Time.time - time > 0.5f)
            {
               // time = 0f;
                count = 0;
            }
          
           

        }
	}

}

你可能感兴趣的:(Unity3D)