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 取消勾选可以避免。 3 Y: Q0 R E! ^$ w" G1 K
V" s* h1 j$ x+ B# E* d3 @
unity点击UI跟场景不冲突的方法: - T4 {! E, @4 G4 f4 s& q9 d 在射线检测后加!EventSystem.current.IsPointerOverGameObject()即可,需要引入命名空间using UnityEngine.EventSystems; J: G8 d5 b3 k/ D, ` l9 G( A ) a: G3 I8 k: B) p. ^- C0 `6 p4 r: o! k" ?3 _6 |