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 取消勾选可以避免。9 ]* v, A% g/ X6 j6 A/ u7 M : U; p2 O1 p) q/ l( t# d% s$ \" junity点击UI跟场景不冲突的方法: " Z: R$ K* {& E( u- p8 W 在射线检测后加!EventSystem.current.IsPointerOverGameObject()即可,需要引入命名空间using UnityEngine.EventSystems; * ^9 i% e+ Z2 D. W) R, H7 h
3 F/ `/ @6 B3 O3 N1 U+ j5 L
% x8 _+ Z& Q; Y6 N, z6 t( k