Super Knight : Enter the Dungeon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.2 KiB

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Serialization;
public class FuntionRepeat : MonoBehaviour
{
public float duration = 1f;
public float tick = 0.1f;
[Serializable]
public class RepeatEvent : UnityEvent { }
[FormerlySerializedAs("onRepeat")]
[SerializeField]
private RepeatEvent m_OnRepeat = new RepeatEvent();
public RepeatEvent OnRepeat
{
get { return m_OnRepeat; }
set { m_OnRepeat = value; }
}
[Serializable]
public class RepeatEndEvent : UnityEvent { }
[FormerlySerializedAs("onRepeatEnd")]
[SerializeField]
private RepeatEndEvent m_OnRepeatEnd = new RepeatEndEvent();
public RepeatEndEvent OnRepeatEnd
{
get { return m_OnRepeatEnd; }
set { m_OnRepeatEnd = value; }
}
public void Play()
{
CancelInvoke();
timeSum = 0;
InvokeRepeating("Blink", 0, tick);
}
float timeSum = 0;
void Blink()
{
OnRepeat.Invoke();
timeSum += tick;
if (duration < timeSum)
{
CancelInvoke();
OnRepeatEnd.Invoke();
}
}
}