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 取消勾选可以避免。7 v! ~7 ]0 S" T0 r% @3 I' ^1 e 2 [5 ]* w* C) h/ a9 Yunity点击UI跟场景不冲突的方法:8 V: X2 B/ A' x, P' M p- \ ]
在射线检测后加!EventSystem.current.IsPointerOverGameObject()即可,需要引入命名空间using UnityEngine.EventSystems;! M- _ O1 K M4 f % e8 n9 x6 o" @4 a" J* _, c' @$ W3 ?7 V; t! W: k