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 取消勾选可以避免。 ! k9 H3 M8 r# G) Q7 T; H& [7 y
$ D! }1 m% j! z H3 m9 W$ U# X2 p
unity点击UI跟场景不冲突的方法: ) i6 |. Y- y. y/ _$ d- t$ d& D 在射线检测后加!EventSystem.current.IsPointerOverGameObject()即可,需要引入命名空间using UnityEngine.EventSystems; F1 m- y% V6 m) e* U& n6 v; } " O3 B2 s, W7 r: p2 ~, t2 l6 s8 ~4 K$ K' e5 b* U6 T- B+ K2 Q