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 取消勾选可以避免。 3 c" z8 |% X+ Q0 T' U+ A% l: F |6 _$ Y+ z V3 f6 |% r% t: A) R* `$ iunity点击UI跟场景不冲突的方法: 9 d0 o1 Y3 F- s& J. o9 U 在射线检测后加!EventSystem.current.IsPointerOverGameObject()即可,需要引入命名空间using UnityEngine.EventSystems; $ N/ ]" d% T/ I: l5 y6 H4 c 0 p0 m5 c e' s9 n/ c$ c3 n' { f' `) j1 w