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 取消勾选可以避免。) f/ g7 V1 O6 ^( h# ^ i + v/ w6 W9 X2 Z0 K0 N- {unity点击UI跟场景不冲突的方法: - Q, h$ ]& c* U4 b1 g/ H* C 在射线检测后加!EventSystem.current.IsPointerOverGameObject()即可,需要引入命名空间using UnityEngine.EventSystems;* J" u- m+ Q3 l 9 e2 P* A& _$ l' w, t% i / p! s- U2 H7 y