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 取消勾选可以避免。 1 { [" @: h1 d, d) z- h0 J
) ?5 t3 @0 c* J
unity点击UI跟场景不冲突的方法:8 p$ ?6 {; C# s4 O9 i
在射线检测后加!EventSystem.current.IsPointerOverGameObject()即可,需要引入命名空间using UnityEngine.EventSystems;7 A T( y; J7 p Y* x0 D8 E* o 9 O& `7 D' D. T2 z) o8 r" f& a0 j% n- X5 |1 Q+ J" W