- Home /
Calling a method once in update
Sup everyone, does calling a method once in update safe? So basically I have a conditional statement inside Update that checks if the player is dead then I want to call an event and execute subscribed methods of it
private bool isDead = false;
if(health < 0.01f && !isDead){
GameEvents.i.PlayerIsDead();
isDead = true;
}
Something like that, is this safe? Safe in a way that it doesn't cost performance issue. I'm making an android game btw, sorry for this stupid question hope you understand ^_^
Answer by Chimer0s · Jan 23 at 08:19 AM
Yeah that's fine. It's a pretty standard way of doing things, though it would probably be better to handle it in a method that updates the health value rather than checking every frame. Ideally you'd have any incoming damage call a method in your script like "TakeDamage(float damage)" or something similar and when that's called you could just check to see if the updated value is less than or equal to 0.
This.
Doing what you do in Update
works and is "ok" but doing things event based is way better.
Your answer
Follow this Question
Related Questions
Call A Function At A Certain Time 1 Answer
Run function once, is this method appropriate? 2 Answers
summing up items price in runtime 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers