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 取消勾选可以避免。 / M0 a2 E6 i9 Y; ?5 k: i: F0 f' s
g' O' O5 K" a6 w* ~
unity点击UI跟场景不冲突的方法:3 w$ F1 P" \- h" M4 O$ _- {6 f: s8 f
在射线检测后加!EventSystem.current.IsPointerOverGameObject()即可,需要引入命名空间using UnityEngine.EventSystems;* y. ^0 T% |5 |: Z$ N5 R
7 j8 |$ ?8 H6 R m( I3 X6 J, [
2 t% o+ \6 E) @/ v+ T