Different way to detect end game

Instead of using a static method to detect the end game, I used this code in the level manager update method:
Brick[] last = GameObject.FindObjectsOfType();
if (last.Length == 0)
{
LoadNextLevel();
}

I removed the Brick script from the unbreakable bricks since it only destroys bricks.

I know this will run every frame but it seems to be a lot simpler code and less prone to error. The static approach will break if you lose and try again. Is there any other pros/cons to the two solutions?

Hi Matt,

Well done for giving alternative approach a go.

Regarding you query about pros/cons - Finding objects is expensive from a performance perspective, so typically something you do as infrequently as possible, often caching the references to objects once found. As such I wouldn’t recommend finding them in an Update method.


See also;

Privacy & Terms