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 取消勾选可以避免。4 F I% g8 O+ ?7 U7 g6 {
" S2 A( p9 A) a+ F3 u8 q! D
unity点击UI跟场景不冲突的方法:9 l/ D h' D, e1 r& d
在射线检测后加!EventSystem.current.IsPointerOverGameObject()即可,需要引入命名空间using UnityEngine.EventSystems;: `. A4 l6 o2 s4 P; V; R5 ~' i
4 s8 u7 G: {* V1 U3 \: T0 m