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 取消勾选可以避免。5 b$ @/ i, i' H7 m2 e% S6 P * I4 Q$ C; ?: A8 |- z2 U# lunity点击UI跟场景不冲突的方法: ; T8 j j* t5 f 在射线检测后加!EventSystem.current.IsPointerOverGameObject()即可,需要引入命名空间using UnityEngine.EventSystems; $ v/ T$ e) [9 Y1 J5 {2 K# e
5 p" x1 _2 Z. {/ Z( y
; ?$ c' j8 \. P- Y. q% z' D