using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
using UnityEngine.EventSystems;
public class PlayerController : MonoBehaviour
{
private void Update()
{
if (EventSystem.current.IsPointerOverGameObject()) return;
if (Input.GetMouseButtonDown(0))
{
Debug.Log("点击屏幕");
}
}
}
这个方法会将点击Text的时候也会当作点击UI,将raycast target 取消勾选可以避免。 " q. Z5 Z! L$ r* o ! B- u( d3 D( A& Junity点击UI跟场景不冲突的方法:8 `% `( w& d- K: ]3 A9 s j" @; |
在射线检测后加!EventSystem.current.IsPointerOverGameObject()即可,需要引入命名空间using UnityEngine.EventSystems;+ H& E* i. N- |, v0 j- h' `) z
* E8 f1 V( N' k, P* p# X% @
8 S. K2 T# G# P3 d