unity中实现监听鼠标的进入和退出某一个UI按钮

using UnityEngine;
using System.Collections;
using Assets.Code.myclass;
using UnityEngine.UI;
using DG.Tweening;
using UnityEngine.EventSystems;

public class ButtonEventTriggerListener : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
  //单例模式
static ButtonEventTriggerListener buttonEvent_this; public static ButtonEventTriggerListener Instance() { if (buttonEvent_this == null) { buttonEvent_this = new ButtonEventTriggerListener(); } return buttonEvent_this; }
private float origiValue; private float endValue = 205; private GameObject btnBcak; private string mainPanelPath = "mainControllerPanel(Clone)/back/menuPanel/"; public void Start() { btnBcak = GameObject.Find(mainPanelPath + "RoamBack").gameObject; origiValue = btnBcak.transform.position.x; } public void OnPointerEnter(PointerEventData eventData) { Debug.LogError("进入"); btnBcak.transform.DOLocalMoveX(endValue, 0.5f); } public void OnPointerExit(PointerEventData eventData) { Debug.LogError("退出"); btnBcak.transform.DOLocalMoveX(origiValue, 0.5f); } }

 

posted @ 2017-10-26 09:17  U3DEngineer  阅读(5517)  评论(0编辑  收藏  举报