MayHeCome/Assets/Scripts/SideScrollingBar.cs
2024-12-18 17:55:34 +08:00

35 lines
816 B
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
public class SideScrollingBar : MonoBehaviour, IPointerDownHandler, IPointerEnterHandler, IPointerExitHandler
{
public float ScrollingSpeed = 0;
public UnityEvent<float> OnHover;
private bool _over = false;
public void OnPointerDown(PointerEventData eventData)
{
OnHover?.Invoke(ScrollingSpeed);
}
private void Update()
{
if (!_over) return;
OnHover?.Invoke(ScrollingSpeed);
}
void IPointerEnterHandler.OnPointerEnter(PointerEventData eventData)
{
_over = true;
}
void IPointerExitHandler.OnPointerExit(PointerEventData eventData)
{
_over = false;
}
}