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 取消勾选可以避免。" P9 z7 \+ z. V : A/ T8 k( Y) runity点击UI跟场景不冲突的方法:: ?! U! u/ x" I1 S. Y2 d% H* A. h
在射线检测后加!EventSystem.current.IsPointerOverGameObject()即可,需要引入命名空间using UnityEngine.EventSystems; 2 j4 @. j1 e! B3 w3 t$ t 8 F9 x1 Y' @8 d2 F1 G 9 u/ N; q) v" ^