using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
/// <summary>
/// 双击脚本
/// </summary>
public class DoubleReturnUI : MonoBehaviour, IPointerClickHandler
{
public Text tt;
private bool b = false;
void OnGUI()
{
if (Event.current.isMouse && Event.current.type == EventType.MouseDown && Event.current.clickCount == 2)
{
if (b)
{
print("double click " + transform.name);
}
}
}
private void Update()
{
//if (Input.GetMouseButton(0))
//{
// Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
// RaycastHit hit;
// if (Physics.Raycast(ray,out hit))
// {
// if (Input.touchCount==1&&Input.GetTouch(0).phase==TouchPhase.Began)
// {
// if (Input.GetTouch(0).tapCount==2)
// {
// tt.text = "双击";
// }
// }
// }
//}
}
float t1;
float t2;
public void OnPointerClick(PointerEventData eventData)
{
t2 = Time.realtimeSinceStartup;
if (t2 - t1 < 0.2)
{
//tt.text = "双击";
}
t1 = t2;
}
public void OnMouseEnter()
{
b = true;
}
public void OnMouseExit()
{
b = false;
}
}
Unity双击
最新推荐文章于 2024-03-19 15:17:38 发布