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 取消勾选可以避免。 & R# G6 ~8 X+ \, E
, a" j3 K( u* a7 d
unity点击UI跟场景不冲突的方法:! D0 h6 H0 l4 I! m3 S2 `7 k7 h* Q9 s
在射线检测后加!EventSystem.current.IsPointerOverGameObject()即可,需要引入命名空间using UnityEngine.EventSystems;2 T% @ b8 X, l$ A/ G$ W 3 f' n5 I+ O& m- @4 x' J* l 4 X$ F# |3 R: S1 ^! W% {8 b V