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 取消勾选可以避免。 9 s- L9 e, ~9 C7 s
1 ]( I; _) t0 d" \. o- G+ y8 d
unity点击UI跟场景不冲突的方法: - Y2 S. L* o) g n; {9 F 在射线检测后加!EventSystem.current.IsPointerOverGameObject()即可,需要引入命名空间using UnityEngine.EventSystems;. x) A! C) p3 v7 i
3 H9 q. [$ x" y) I: I2 |
y/ E. w8 S3 o1 H