注意:要双击的物体上一定要有碰撞器,并且碰撞器和本脚本挂在同一个物体上。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class UnadaptedTransitTrain_Script : MonoBehaviour
{
private float _prevouseClick;
// Use this for initialization
void Start () {
_prevouseClick = Time.realtimeSinceStartup;
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonUp(0))
{
RaycastHit hit;
if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit) && hit.transform == transform)
{
if ((Time.realtimeSinceStartup - _prevouseClick) < 0.2f)
{
//注意:要双击的物体上一定要有碰撞器,并且碰撞器和本脚本挂在同一个物体上
Debug.Log("双击");
}
else
{
_prevouseClick = Time.realtimeSinceStartup;
}
}
}
}
}