Reputation: 15
I made it a habit to program "looping" code in the manner shown bellow. I am a self taught coder, and I am just wondering if it is really necessary or not. (This example is in Unity C#):
Example: Will this:
void Update()
{
//GameOver Procedure
if(shipCurrentHP <= 0 && GameOver == false)
{
StartCoroutine(BlowUp());
GameOver = true;
}
}
Be any better than this?:
void Update()
{
//GameOver Procedure
if(shipCurrentHP <= 0)
{
StartCoroutine(BlowUp());
GameOver = true;
}
}
Upvotes: 0
Views: 95
Reputation: 5035
Your second example will start another coroutine in every frame after the condidion is initially met, it will most likely just eat up all the RAM of the machine if the user does nothing after that point. Generally doing stuff in Update should be avoided unless you are doing somethign that actually needs to execute every frame
Upvotes: 1