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 取消勾选可以避免。 3 B l& W5 K) {% r7 V) Y) p8 K ' y6 y5 E0 g' u+ w4 o4 s, V) Funity点击UI跟场景不冲突的方法:0 v4 G4 l& e1 R0 e) U, V9 O! h
在射线检测后加!EventSystem.current.IsPointerOverGameObject()即可,需要引入命名空间using UnityEngine.EventSystems;# X7 _/ }" P. R& R' k
, ~5 S3 ~# W4 g8 }. Y