Brick count

I’m not sure why during the course, they add a tag to annotate if a brick is breakable but when keeping track of how many bricks are left, they don’t use that. Instead they use a static to keep track of the amount of bricks left. This seems odd as the solutions seems more cumbersome as when using the FindGameObjectsWithTag in combination with the OnDestroy method:

I have implemented this in my LevelManager:

public void brickDestroyed() {
    int bricksLeft = GameObject.FindGameObjectsWithTag("Breakable").Length;
    Debug.Log("Bricks: " + bricksLeft);

And in my Brick I have this:

void OnDestroy() {

By using the OnDestroy, you are sure that it’s called at the correct time and no need to keep track of the numbers yourself…
Without the OnDestroy, the FindGameObjectsWithTag is not reliable as we need to wait before the object is destroyed, that’s why we call the LevelManager in the OnDestroy method.

Privacy & Terms