Skip to content

Instantly share code, notes, and snippets.

@inoook
Last active January 24, 2025 02:01
Show Gist options
  • Save inoook/c2f7b7620276f1e30747ed94273659bb to your computer and use it in GitHub Desktop.
Save inoook/c2f7b7620276f1e30747ed94273659bb to your computer and use it in GitHub Desktop.
/**
[SerializeField] TimerAct logTimerAct = default;
private void Start()
{
logTimerAct.Act = Act;
}
private void Update()
{
logTimerAct.Process(Time.deltaTime);
}
void Act()
{
// Do something...
}
**/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class TimedActionProcess
{
[SerializeField] bool enable = true;
[Tooltip("Sec この秒数ごとに送信")]
[SerializeField] float rate = 1;
float time = 0;
public System.Action Act = null;
public void Enable(bool v)
{
enable = v;
time = 0;
}
public void Process(float deltaTime)
{
if (!enable) { return; }
float delta = rate;
time += deltaTime;
if (time > delta)
{
time = time - delta;
Act?.Invoke();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment