首页 > 编程语言 > 详细

Unity3D 判断鼠标是否按在UGUI上

时间:2016-09-01 01:52:42      阅读:547      评论:0      收藏:0      [点我收藏+]

判断鼠标是否点击在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(0)||(Input.touchCount >0 && Input.GetTouch(0).phase == TouchPhase.Began))
        {
#if IPHONE || ANDROID
            if (EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
#else
            if (EventSystem.current.IsPointerOverGameObject())
#endif
                Debug.Log("当前触摸在UI上");
            
            else 
                Debug.Log("当前没有触摸在UI上");
        }
    }
}

方法来自:http://www.xuanyusong.com/archives/3327

Unity3D 判断鼠标是否按在UGUI上

原文:http://www.cnblogs.com/sunxun/p/5828009.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!