- Home /
A better solution than the obvious single-frame hack in update mode or IEnumerator
I'm looking for something better than this:
bool tick;
void Update ()
{
if (tick)
{
// Insert code here
tick = false;
}
}
// User input executes this method
public void DoOneFrameTick ()
{
tick = true;
}
Or this:
public IEnumerator OneTickFrame ()
{
tick = true;
yield return null;
tick = false;
}
I need something if activated, is only true for 1 single frame, no matter where it's placed. If only a method would exist in which you could put any parameter you want and let it return that value for just one frame.
Like (pseudo):
bool Attacked;
void Update () {
if (Attacked)
{
player.health -= ExecuteOnce(0.15f);
}
}
So see here, imagine the enemy's attack to take a little longer than a frame. "Attack" would stay on longer than we want but the "ExecuteOnce" method saves the day. And as soon as "Attack" turns false again the method stops executing. Soon as the method starts executing again, it'll execute one frame again and then returns null again.
Would something magical like this be possible? Or is there something better?
Your answer
Follow this Question
Related Questions
Decrease a value over time? 2 Answers
Target frame rate between scenes 1 Answer
Time Delay Animation 1 Answer
Is it possible to change the Frame Over Time property of a ParticleEmitter at runtime? 0 Answers
All AI animations stop on first frame 0 Answers