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 取消勾选可以避免。 ( E- r" y/ N7 h 1 _1 b& }+ W4 l' ~! [6 nunity点击UI跟场景不冲突的方法: 9 {+ g) { |, D1 Y3 G 在射线检测后加!EventSystem.current.IsPointerOverGameObject()即可,需要引入命名空间using UnityEngine.EventSystems; " J! S! ]! |) Z6 g( l
, D- `8 Z: N ]/ ~* D
! a. W; t% ^/ c/ m9 o* E2 D+ G