About 'Win The Level & Load'!


#1

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!


#2

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.


#3

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.


#4

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:


#5

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?


#6

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


#7

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:


#8

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.


#9

Hi @Rick_Davidson and everybody,

As you mentioned when you explained about the Start method and that this functions is called within the initialization of the the scene. There is something that i’m not sure about and I have some doubts about.
The question is about the increment statement, how can you be sure that the blocks are NOT rendered in parallel so that the increment statement works well, in other words why don’t you use an ATOMIC increment statement for this variable to make sure that at the final stage (when all the blocks are rendered) the value of this variable is right ?


#10

I believe you are talking about the incremement statement which counts up how many blocks we have in the scene. If so, its not so much of a problem in terms of how and when each block is incrementing the variable, but simply that when the start method in each block’s script is called, it says “add 1 to the total”. We know that all blocks will be called at some point and we know that it will only be called once, so we are pretty sure that the total will be accurate.


#11

Thanks for the answer, but the question is how can you be sure that 2 blocks or more have NOT called the the increment statement from two different Block functions simultaneously, so why don’t you use a Mutex, why there is no race condition?

Another question that may explain more the first question :slight_smile:
how the rendering for the objects is called? by hierarchy? randomly? or can’t say? and what about the object which can be found in the same GameObject (like the blocks that can e found under the GameObject called Blocks) .

Thanks


#12

I’m not sure I fully understand your question. But check out the Unity execution order documents, that may help you see when and how things are called / rendered / executed. Scroll down to the diagram in this page: https://docs.unity3d.com/Manual/ExecutionOrder.html