I have a series of event being triggered from a main loop, which keeps track of time and functions as a clock. For some trivial functions, I want them to occur bound by this clock, but don't need to fire every tick. My solution is
private IEnumerator regenProc(float deltaTime)
{
float elapsedTime = deltaTime;
while (elapsedTime < 0.5f)
{
yield return null;
elapsedTime += deltaTime;
}
CurrentValue += elapsedTime * (MaxValue * regenPercent + regenFlat);
but that feels ugly and clunky, I would prefer the return type to just be void like I want it to be.
private void regenProc (float deltaTime)
{
static float elapsedTime += deltaTime;
if(elapsedTime < 0.5f)
return
CurrentValue += elapsedTime * (MaxValue * regenPercent + regenFlat);
}
would be cleaner and simpler, back in C++ days, but this technology seems missing. Is there a way to achieve this functionality which is.
- Purely native to the method (it has to work inside delegates, and not conflict with other instances)
- Not an enumerator
- Not a feature removed by C# for some reason