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 取消勾选可以避免。7 v9 y7 }; S7 O9 M- a' ^, l7 f
% S- c. ]4 @4 m/ D2 ]/ a3 \% ]; Q
unity点击UI跟场景不冲突的方法: * g3 d7 u' M: `$ @( a2 S7 C9 E 在射线检测后加!EventSystem.current.IsPointerOverGameObject()即可,需要引入命名空间using UnityEngine.EventSystems; ' A5 y4 q% @; Y: ^$ R! N% d9 O
4 M6 I; k6 T \! y/ H8 |4 y c1 g
^; f$ y) F$ R; O7 _' [/ J6 L" A% Z