‫Welcome back.
‫Currently, we have the behavior in our game that whenever we hit one bomb or any bomb, then the game
‫just stops.
‫And that's not really the best behavior we want to have.
‫The one that we want to have is, of course, a game over screen or something like that.
‫And in our case, I think the best choice is to stop the game in the background and at the same time
‫open up a panel which bill will display that is game over and will allow us to restart the game.
‫That's what we're going to build in this video.
‫So let's go ahead and create a panel now.
‫I don't want to stretch it.
‫I want to center the panel and let's make it 500 wide and maybe 250 high.
‫So that's going to be our panel now.
‫And let's add a text into the panel UI text that will be inside of the panel.
‫Let's center that in both directions.
‫Then let's maybe change well, let's position it towards the top of the panel.
‫And now let's set zero.
‫Set that to zero.
‫Actually, let's drag that down a little.
‫It's best maybe in the scene view where actually let's change the value a little bit to let's say -30
‫or 40.
‫I think that should be fine.
‫Now let's change the font size to something like 48.
‫Now, of course, we don't see it because the height is only 30.
‫So what we can do is overflow vertically and horizontally.
‫Now we see that and that should show game over and maybe even with an empty space in between.
‫So the panel is not a panel anymore.
‫It's a game over panel now.
‫So let's name it that way.
‫And the text should maybe also be game over text.
‫All right.
‫So now that's the panel and we will activate or deactivate the panel based on the game state.
‫So if it's game over, we want to see the game over panel.
‫And if it's not game over, then we, of course, don't want to see it.
‫All right.
‫So let's take care of the activating and and activating it in our game manager script.
‫So let's open up our game manager.
‫And in here currently we only have increased score and we have our on bump head and what we will need
‫is a new game object.
‫So I'm going to call that public game object game over panel.
‫So that's going to be our game over panel.
‫And while we're at it, let's make it a little nicer by adding a header.
‫This one will be score elements.
‫And that one here will be header game over.
‫You will see what that means in a second.
‫So let's go there and go to our game manager and in a second it will change.
‫So it needs to update.
‫And as you can see, score elements.
‫That's the header.
‫So this bold black text here, score element and that's the other header called Game Over.
‫Now we need game over panel.
‫So let's get that.
‫Let's drag it right in there.
‫And what we want to do in our game manager is to deactivate our game over panel whenever we start the
‫game.
‫So it's best to do that in a wake.
‫So there we set the game over panel to set active of on to false so what that does it says okay set
‫it to active but actually set it false active which is deactivated.
‫So the game over panel will be deactivated on a wake.
‫So let's quickly check that out.
‫We start the game.
‫All right.
‫So try that.
‫Let's try that play and we see it disappears.
‫Great.
‫So when do we want it to appear?
‫Well, actually, whenever we stop the game.
‫So here, game over, panel.
‫Set active.
‫True.
‫So that will allow us to see the game over area.
‫So this whole panel, with all its information, whenever we lose the game.
‫So let's get there.
‫Let's try to hit the bump.
‫And I hit the bump.
‫The game was paused.
‫We can see it in the background.
‫It's very nice.
‫And we have this little area here which says Game over.
‫Now, of course, we need a button on it and some further objects as well.
‫For example, the score would be nice to see here.
‫So let's go ahead and add the score.
‫And by that, I mean let's duplicate the game over text and changed it to score text and let's drag
‫the score text further down to -100 maybe.
‫Yeah.
‫Let's reduce the font size to 30.
‫Let's see how that looks.
‫Yeah, that's already quite good.
‫Maybe 100, maybe -80.
‫It should be better.
‫And the text should say something like score zero.
‫All right.
‫But then we want to do that programmatically, of course.
‫So in here, what we'll need is to set the text of our game over.
‫Panel cortex actually will need a new variable for that.
‫So let's create one.
‫Let's call it
‫public text.
‫Game over panel, score text.
‫Quite a long name, but it's very descriptive.
‫And then we use that game over panel score text in order to set the score
‫into it.
‫So score to string.
‫All right, so let's try that.
‫And actually we shouldn't try that because we need to assign it.
‫So let's get to a game manager and drag our score text into the game manager here.
‫So not the one from the canvas directory.
‫Maybe we should even rename it to game over label score text.
‫All right, it's in there.
‫And now let's try to hit one point and at the same time hit the bump.
‫And as you can see, three is a text here.
‫Now, of course, we want to have something like score zero or score three there.
‫So we need to edit it a little bit.
‫So let's go in here and change that to score.
‫Colon, empty space, plus the score.
‫All right.
‫So that will fix it.
‫We can quickly check that again.
‫I'm trying to bomp and score at the same time.
‫So score and bom and we see score three.
‫Next we want to add a restart button in here.
‫So let's go ahead and do that.
‫Create UI because that button will allow us to restart the game and then we can go ahead and play some
‫more.
‫So let's change the position just a little bit, actually.
‫Let's go.
‫-50.
‫That should be fine.
‫Now let's change the text to restart.
‫And what I want to do is I want to set this time scale on one whenever somebody pressed the button.
‫So let's play voit restart game and I set the time scale
‫to one.
‫So let's test that.
‫Let's see if that button works.
‫Okay.
‫So now we, of course, need the button.
‫So let's go ahead and go to the restart button.
‫And in here, let's add the on click event that's drag the game manager in here.
‫So now we will have the functionality of the game manager, which is, for example, restart game.
‫So what that will do is it will restart the game as we've just seen, or at least in this case it will
‫set the speed to or a time scale to one again.
‫So let's try that.
‫Let's hit the bump and let's press restart.
‫And you can see that the game goes on in the background until we hit the bump again.
‫And of course, we want not only to do that, we also want to restart the game in terms of getting rid
‫of all the game objects and resetting the score.
‫All right.
‫So let's go back to the script.
‫And in the restart game method, we all need to set the score back to zero.
‫So as soon as we restart the game, there are multiple things of course we need to do.
‫Reset the score, set the score, text back to zero D, activate the panel, then set the text of the
‫panel back to zero and destroy all the game objects.
‫So let's do that.
‫Score is zero.
‫Score text.
‫Text is set to zero as well.
‫Then our game over panel should be deactivated.
‫So it's set to false and our game over panel score text can be set back to score colon zero.
‫Now finally, we need to destroy all the game objects in our game, at least the ones that are interacting
‫with.
‫And we can do that the following way.
‫Game object.
‫I'm going to call a G in game object, find
‫game object with tag and actually the plural game objects with tag.
‫And now we need to enter a tag and I'm going to use the tag enter EC to bowl.
‫And for all the objects that are intractable, I want to destroy them.
‫So what does that mean?
‫Well, let's have a look in unity, then we'll make that will make sense.
‫So our prefabs, in our case, the Bomp and the orange and the orange cut, they all need a tag.
‫Let's add a tag by going to untagged here, then add tag and then pressing this little plus button here
‫that will allow us to add a new tag to our list.
‫And I'm going to call it Enter to Bowl.
‫Save that and now I need to assign that to our bomp.
‫And what else is interactive?
‫Well, our orange.
‫And our orange cut.
‫So that bond here is intractable as well.
‫All right.
‫And the orange is so as well, because the prefabs are so now.
‫Whenever.
‫I restart the game.
‫Every single object that has the tag intractable will be destroyed.
‫That's what this code here says, those three lines.
‫So it loops through all the game objects in our game which have this tag and then it destroys them.
‫All right, so let's try that.
‫Let's see what happens.
‫So I'm going to play a little bit, get some points until the bomb comes.
‫And I want to hit the first bomb that comes up.
‫And there it is.
‫I hit the bump.
‫Now let's press restart.
‫And we see all the objects were destroyed.
‫Our score was set to zero and we are back in the game.
‫Now, let's have a look here at the right hand side at the hierarchy.
‫Be careful.
‫I press restart and you can see all of them are destroyed.
‫And the new ones, of course, spawn directly.
‫All right.
‫Now we know how to start the game, how to restart the game, and how to get rid of all the objects
‫in our game, reset the whole state, pause the game and so forth.
‫In the next video, we are going to add the high score to our game.
‫So we have this best zero, but we don't save anything yet.
‫So let's do that.