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 取消勾选可以避免。 : p7 M8 H6 s" D8 o' O: H! ~+ b * _! `, A7 [" t1 x0 b/ V3 ~1 Kunity点击UI跟场景不冲突的方法:' T( `' l: M( O+ S( C9 J* v& x
在射线检测后加!EventSystem.current.IsPointerOverGameObject()即可,需要引入命名空间using UnityEngine.EventSystems; . Q% I7 c4 H- r6 p% n. D! b7 w 1 V: d- t, i' u U: [. X) G) H6 S3 P+ K. j/ V' l, o8 V