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 取消勾选可以避免。 # |/ W3 J& e2 B1 t0 ]0 Y
( ~3 n0 Z( E7 z* Q9 P
unity点击UI跟场景不冲突的方法:" h& @: O4 V9 a! e
在射线检测后加!EventSystem.current.IsPointerOverGameObject()即可,需要引入命名空间using UnityEngine.EventSystems; 5 d Z2 j' c, J& R: H
7 x5 ^8 V! @8 G- F2 a9 K5 n
; t/ t7 L q9 Q. M a. T, z u