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); } }

 

转载于:https://www.cnblogs.com/Study088/p/7735203.html

你可能感兴趣的:(unity中实现监听鼠标的进入和退出某一个UI按钮)