‫Welcome back.
‫In this video, we are going to create the first part of our game scene and we're going to move over
‫from this scene to the next to the next scene by using our play button.
‫In order for our play button to do anything, we need to add a script to it, otherwise it won't do
‫anything.
‫So we need to create a new script.
‫So I press right click, create a new script, and I'm just going to call that one play button because
‫I'm going to keep it very simple with the scripts in this video, because in the end it's easier to
‫create multiple scripts that do each, only one thing or have only one important aspect that they have
‫to fulfill.
‫And that's the same with this play button.
‫So this script will only take care of this one button, and the only thing that it should do is take
‫us from this scene to the next scene.
‫Let's first start with giving this play button any functionality at all.
‫And how we do that is we create a new method.
‫And the method that I'm going to create is public void and I'm going to use that play game name.
‫So I create a new method that I call play game and it's with a capital P because methods in C-sharp
‫are written with capital letters.
‫And then for now, I'm just going to use the debug functionality debug log play game was pressed.
‫So that's it.
‫That's all the code that we're going to use for now.
‫The only thing that this is going to do is create an entry into our console.
‫So let's save that script with control as or command s and then let's go to our play button again within
‫our main menu.
‫We have the button here.
‫And in there, on the right hand side, in the button script component, you can see that there is an
‫on click area and there's the list is empty currently.
‫So what we do is we add something to the list, so we press the plus button and here we can choose an
‫object.
‫And currently we could choose either from the scene or we could choose from the assets.
‫The best way to handle it is to drag that script into our button itself.
‫Now you can see that the play button script is added to our button here.
‫Now we can choose the button itself as the on click on Click Object.
‫And within there we can now choose the play button functionality, which was called Play Game.
‫As you can see, there are multiple different methods which are automatically enabled and one of them
‫is the one that we created ourself, which is called play game.
‫So now let's add that and now let's test the game.
‫Let's simply test what play that button does.
‫And I click on the play button.
‫At the left hand side you can see play game was pressed perfect.
‫That's exactly what we wanted to achieve.
‫And now we know that the button works and we can go ahead and use that button in order to move us from
‫this scene to the next scene.
‫And in order to do that, we need to create a new scene.
‫So let's save the scene in here.
‫And now let's create a new scene.
‫So right click within your assets, create and then go to scene.
‫And this scene is going to be our game scene and there will be the whole game functionality.
‫So let's move over to the scene and you can see it's empty.
‫So there's nothing happening in this scene.
‫And then here you see we have the same setup as we did with the other scene at the beginning.
‫What I would like to have is the same main camera with the same background and the same size as I had
‫in the other video, whereas I have in my main menu scene and you might guess how to achieve that,
‫how to get it over here.
‫And I'm going to show you.
‫So we go back to our main menu scene and in there I.
‫Use my main camera and I create a prefab out of it.
‫So I drag it into my assets, into my assets area.
‫And you can see my main camera is a prefab.
‫Now at the bottom you can see main camera dot prefab.
‫So that means it's a prefabricated, which we can now use in multiple, multiple ways.
‫For example, we could go back to our game scene.
‫And within our game scene we can delete the old main camera.
‫So now you can see display one, no cameras rendering, and we can drag our main camera inside there.
‫And you can see that it has all the different settings that we set up.
‫So 450 for the size.
‫It has a background which is our quad and it has a black material.
‫Now let's save the game scene and go back to our main menu.
‫Now we want to move from here to our game scene.
‫And in order to achieve that, we need to add some code.
‫So for now, our play button really just does one thing and it says play game was pressed in the debug
‫log, but what we need to add is our scene manager and in order to use the scene manager we need to
‫implement functionality.
‫So we add a library here which is unity engine dot scene management within this namespace scene management
‫that we can find the scene manager.
‫So now we can call the scene manager class.
‫Which allows us to move from one scene to another.
‫So we say load scene and now we can move from this scene to the next scene.
‫And the next scene that we want to move to is our game scene.
‫And here it's important to use a string.
‫As you can see, it expects a string as which is the scene name.
‫And it's important to have a scene which is called game.
‫Otherwise we will get an error that says no scene available with the name you entered.
‫So this one, the scene manager, moves us to the game scene.
‫So that's the idea behind it.
‫So I save the script, I go back to Unity, and now I start to play the game.
‫And I press the play button.
‫So that we are.
‫Let's press play.
‫And we get an error still.
‫It says seen game could not be loaded because it has not been added to the build settings or the asset
‫bundle has not been loaded.
‫If you ever get this error where it says could not be loaded because it has not been added to the build
‫setting.
‫You have to add it to the build setting and it's very easily done.
‫We go to file, then build settings or in my case on Mac, it's shift command B and then I go to the
‫build settings in here.
‫I have to add the scenes that I want to have in my build, and you can drag the scenes from your assets
‫folder straight in the scenes and build as soon as you've done that.
‫And then you can start the game and see if that works.
‫So I'm going to maximize and play again so that it goes it goes full screen.
‫And then we are I press play and I get to my black screen and my black screen is my game scene for now.
‫So we saw that it worked.
‫So play game was pressed and we were in the game scene.
‫Perfect.
‫So now you know how to create buttons, how to use buttons, how to move from scene A to scene B.
‫And in the next video, we are going to populate our game scene and clean that one up.
‫All right.
‫Before we do that, let's clean our assets folder because now we create folders for all the different
‫parts of our game in order to keep everything clean.
‫For now, it's not really that necessary because we only have six files or seven files, but it's going
‫to be much more difficult later on or much more important later on, the more complex games get and
‫the more different pieces you have.
‫So what we need to do is create a script folder, a folder for all the scripts, and I drag my play
‫button script in there, and then the next one is for my prefabs.
‫It's always important to have a prefabs prefabricated folder.
‫So I drag my main camera in there, then I create one for fonts
‫and I drag my Munroe font in there and one for materials, materials and drag my black material in there.
‫So as for the scenes, you can create an additional scenes folder, but what I really like to have is
‫my scenes at one place, which is in the root folder of assets.
‫Great.
‫So now let's save the scene, save the project, and see you in the next video.