rabidus-test/Assets/Scripts/LeanTimer.cs

25 lines
626 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class LeanTimer : MonoBehaviour
{
public UnityEvent<float> OnUpdate = new UnityEvent<float>();
private LTDescr LTDescr;
public void StartTimer(float startValue, float endValue, float time, System.Action OnComplete = null)
{
LTDescr = LeanTween.value(1, 0, time).setOnUpdate((float x) =>
{
OnUpdate?.Invoke(x);
}).setOnComplete(OnComplete);
}
public void StopTimer()
{
if (LTDescr != null)
LeanTween.cancel(LTDescr.id);
}
}