using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class ClickTest : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update()
{
//Debug.Log(EventSystem.current.gameObject.name);
if (Input.GetMouseButtonDown(0))
{
if (CheckGuiRaycastObjects()) return;
RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
if (hit.collider != null)
{
Debug.Log("点击");
}
}
}
///
/// 基于ugui的eventsystem判断是否有ui遮挡
///
///
bool CheckGuiRaycastObjects()
{
PointerEventData eventData = new PointerEventData(EventSystem.current);
eventData.pressPosition = Input.mousePosition;
eventData.position = Input.mousePosition;
List
EventSystem.current.RaycastAll(eventData, list);
//Debug.Log(list.Count);
return list.Count > 0;
}
}
相关阅读
发表评论