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 c. I W2 q6 n; ^ # s2 ], ^ B7 @. r! N# ]unity点击UI跟场景不冲突的方法:2 Z W$ {) {" a$ W! g/ b. C4 n
在射线检测后加!EventSystem.current.IsPointerOverGameObject()即可,需要引入命名空间using UnityEngine.EventSystems; $ r4 ~/ L/ N( x1 z/ I/ w3 J' F
% O; f/ J9 l$ w" `# u' m
, O, B+ C) U, g/ B* i