判断鼠标是否点击在UGUI上
#if UNITY_ANDROID && !UNITY_EDITOR
#define ANDROID
#endif #if UNITY_IPHONE && !UNITY_EDITOR
#define IPHONE
#endif using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using UnityEngine.EventSystems;
public class NewBehaviourScript : MonoBehaviour { // Use this for initialization
void Start () { } void Update()
{
if (Input.GetMouseButtonDown()||(Input.touchCount > && Input.GetTouch().phase == TouchPhase.Began))
{
#if IPHONE || ANDROID
if (EventSystem.current.IsPointerOverGameObject(Input.GetTouch().fingerId))
#else
if (EventSystem.current.IsPointerOverGameObject())
#endif
Debug.Log("当前触摸在UI上"); else
Debug.Log("当前没有触摸在UI上");
}
}
}
方法来自:http://www.xuanyusong.com/archives/3327