About 'Win The Level & Load'!


In this video (objectives)…

  1. Create a public method for decreasing total number of blocks when a block is destroyed.
  2. Use FindObjectOfType to access our level loading methods.

After watching (learning outcomes)… Load the next level when all blocks in a level have been destroyed.

(Unique Video Reference: 22_BR_CUD)

We would love to know…

  • What you found good about this lecture?
  • What we could do better?

Remember that you can reply to this topic, or create a new topic. The easiest way to create a new topic is to follow the link in Resources. That way the topic will…

  • Be in the correct forum (for the course).
  • Be in the right sub-forum (for the section)
  • Have the correct lecture tag.

Enjoy your stay in our thriving community!


Without the Level script, why does the end game screen load once all the blocks are destroyed? The only way the end game screen should load is via the LoseCollider script when we miss the ball and it hits the lose collider.


With our current implementation we only have 1 end game screen. If you like, you can create a win screen and a lose screen. Currently when we finish our last level we are still calling the method which loads next level, which happens to be the game over screen.


Thanks for the reply. I disabled the level script and tried again and this time unity didn’t load the next level or the end game scene. I guess the first time round, I forgot to add level 2 to the build settings. That’s why unity loaded the end game screen. Damn, I feel stupid now :confused:


It’s nice to see that at the start of this lecture you explain how and why the game is able to count the number of blocks. I wish I had watched this first instead of spending 30-40 minutes checking the scripts and going back and forth between Level.cs and Block.cs trying to figure out how it works. I guess it was time well spent.

One question about the variable breakableBlocks. All blocks call CountBreakableBlocks(), adding 1 each time to it (breakableBlocks++), but we never gave breakableBlocks an initial value (in this case 0 would make sense). Will games always assume that non initialized int variables are 0?


Yes, you are correct, if we declare an int but not initialise it then it will default to 0.


Haha, the logic you explained at the start took me alot of head scratching to figure it out on my own, anyways i feel a lot smart now that i figured that out all by my self. :slight_smile:


Thanks for the reply. You are an amazing instructor. I was intimidated when I started the course despite having some knowledge of programming, but all doubts and fears disappeared after I finished the first section. I am looking forward to the rest of the course and then the 3D course.