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 取消勾选可以避免。 ( j: L/ i6 g7 X& Z' {0 U % T5 t K3 @) i x$ gunity点击UI跟场景不冲突的方法: $ i& |; f4 R- W0 B9 z 在射线检测后加!EventSystem.current.IsPointerOverGameObject()即可,需要引入命名空间using UnityEngine.EventSystems;2 U, @- B: M/ N3 z5 ] 4 [! [$ F/ ]0 u2 k6 w: O- a/ l7 c: ~) x! f" K& y) y+ G& p C