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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM