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 取消勾选可以避免。 / N: Z9 W8 o( a2 y0 r+ P( r* W+ C, q
4 Q, r" K2 A/ \' i+ J5 Z3 r
unity点击UI跟场景不冲突的方法: n& y( D3 y$ a0 V+ g& `& L0 e' k/ y 在射线检测后加!EventSystem.current.IsPointerOverGameObject()即可,需要引入命名空间using UnityEngine.EventSystems;: n/ A% ]; J0 {& h, f 1 k( E0 ^/ x- ~" E) V1 K 3 H& q, K, |6 J# ^