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 取消勾选可以避免。 : z8 Z- d3 _& ?; H9 x7 M7 v* k : a1 f4 E, u/ z' N2 b) cunity点击UI跟场景不冲突的方法: 7 F: v) ~8 D: X6 G9 I 在射线检测后加!EventSystem.current.IsPointerOverGameObject()即可,需要引入命名空间using UnityEngine.EventSystems; & t5 `* h9 {+ G' j5 u7 s) K( x5 a
" a1 q& @& C+ X3 t2 ~4 `+ _
+ g6 H3 L' k: A