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 取消勾选可以避免。( \) @2 N8 Y2 x( d) J
9 R& n6 @2 I" r
unity点击UI跟场景不冲突的方法: 0 @* }5 [) U3 D: c; e) @ 在射线检测后加!EventSystem.current.IsPointerOverGameObject()即可,需要引入命名空间using UnityEngine.EventSystems; ( h- g% P7 _. ~+ V 9 x$ S$ `$ m; M: P0 \0 e1 e6 i C