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 list = new List();

EventSystem.current.RaycastAll(eventData, list);

//Debug.Log(list.Count);

return list.Count > 0;

}

}

 

相关阅读

评论可见,请评论后查看内容,谢谢!!!评论后请刷新页面。