Last active
January 24, 2025 02:01
-
-
Save inoook/c2f7b7620276f1e30747ed94273659bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
[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