1 00:00:04,010 --> 00:00:04,730 ‫Welcome back. 2 00:00:04,760 --> 00:00:10,370 ‫In this video, we are going to create the first part of our game scene and we're going to move over 3 00:00:10,370 --> 00:00:15,290 ‫from this scene to the next to the next scene by using our play button. 4 00:00:15,560 --> 00:00:21,920 ‫In order for our play button to do anything, we need to add a script to it, otherwise it won't do 5 00:00:21,920 --> 00:00:22,550 ‫anything. 6 00:00:22,550 --> 00:00:24,530 ‫So we need to create a new script. 7 00:00:24,530 --> 00:00:31,700 ‫So I press right click, create a new script, and I'm just going to call that one play button because 8 00:00:31,700 --> 00:00:36,410 ‫I'm going to keep it very simple with the scripts in this video, because in the end it's easier to 9 00:00:36,410 --> 00:00:43,580 ‫create multiple scripts that do each, only one thing or have only one important aspect that they have 10 00:00:43,580 --> 00:00:44,630 ‫to fulfill. 11 00:00:44,630 --> 00:00:46,670 ‫And that's the same with this play button. 12 00:00:46,670 --> 00:00:53,300 ‫So this script will only take care of this one button, and the only thing that it should do is take 13 00:00:53,300 --> 00:00:55,760 ‫us from this scene to the next scene. 14 00:00:55,940 --> 00:01:00,560 ‫Let's first start with giving this play button any functionality at all. 15 00:01:00,560 --> 00:01:04,550 ‫And how we do that is we create a new method. 16 00:01:04,910 --> 00:01:12,770 ‫And the method that I'm going to create is public void and I'm going to use that play game name. 17 00:01:12,770 --> 00:01:19,550 ‫So I create a new method that I call play game and it's with a capital P because methods in C-sharp 18 00:01:19,550 --> 00:01:22,280 ‫are written with capital letters. 19 00:01:22,280 --> 00:01:32,840 ‫And then for now, I'm just going to use the debug functionality debug log play game was pressed. 20 00:01:34,700 --> 00:01:35,960 ‫So that's it. 21 00:01:35,960 --> 00:01:38,090 ‫That's all the code that we're going to use for now. 22 00:01:38,120 --> 00:01:42,710 ‫The only thing that this is going to do is create an entry into our console. 23 00:01:42,710 --> 00:01:50,210 ‫So let's save that script with control as or command s and then let's go to our play button again within 24 00:01:50,210 --> 00:01:51,140 ‫our main menu. 25 00:01:51,140 --> 00:01:52,430 ‫We have the button here. 26 00:01:54,140 --> 00:01:59,840 ‫And in there, on the right hand side, in the button script component, you can see that there is an 27 00:01:59,840 --> 00:02:05,060 ‫on click area and there's the list is empty currently. 28 00:02:05,120 --> 00:02:10,910 ‫So what we do is we add something to the list, so we press the plus button and here we can choose an 29 00:02:10,910 --> 00:02:11,650 ‫object. 30 00:02:11,660 --> 00:02:15,820 ‫And currently we could choose either from the scene or we could choose from the assets. 31 00:02:15,830 --> 00:02:22,100 ‫The best way to handle it is to drag that script into our button itself. 32 00:02:22,130 --> 00:02:26,810 ‫Now you can see that the play button script is added to our button here. 33 00:02:26,900 --> 00:02:32,750 ‫Now we can choose the button itself as the on click on Click Object. 34 00:02:32,960 --> 00:02:40,220 ‫And within there we can now choose the play button functionality, which was called Play Game. 35 00:02:40,250 --> 00:02:45,740 ‫As you can see, there are multiple different methods which are automatically enabled and one of them 36 00:02:45,740 --> 00:02:49,070 ‫is the one that we created ourself, which is called play game. 37 00:02:49,310 --> 00:02:52,280 ‫So now let's add that and now let's test the game. 38 00:02:52,430 --> 00:02:55,850 ‫Let's simply test what play that button does. 39 00:02:55,940 --> 00:02:57,920 ‫And I click on the play button. 40 00:02:57,990 --> 00:03:04,700 ‫At the left hand side you can see play game was pressed perfect. 41 00:03:04,700 --> 00:03:06,610 ‫That's exactly what we wanted to achieve. 42 00:03:06,620 --> 00:03:12,620 ‫And now we know that the button works and we can go ahead and use that button in order to move us from 43 00:03:12,620 --> 00:03:14,240 ‫this scene to the next scene. 44 00:03:14,480 --> 00:03:17,120 ‫And in order to do that, we need to create a new scene. 45 00:03:17,120 --> 00:03:19,280 ‫So let's save the scene in here. 46 00:03:19,280 --> 00:03:21,650 ‫And now let's create a new scene. 47 00:03:22,450 --> 00:03:27,490 ‫So right click within your assets, create and then go to scene. 48 00:03:27,940 --> 00:03:33,730 ‫And this scene is going to be our game scene and there will be the whole game functionality. 49 00:03:33,730 --> 00:03:37,000 ‫So let's move over to the scene and you can see it's empty. 50 00:03:37,000 --> 00:03:39,250 ‫So there's nothing happening in this scene. 51 00:03:39,790 --> 00:03:44,560 ‫And then here you see we have the same setup as we did with the other scene at the beginning. 52 00:03:44,560 --> 00:03:49,600 ‫What I would like to have is the same main camera with the same background and the same size as I had 53 00:03:49,600 --> 00:03:55,960 ‫in the other video, whereas I have in my main menu scene and you might guess how to achieve that, 54 00:03:55,960 --> 00:03:57,460 ‫how to get it over here. 55 00:03:57,640 --> 00:03:58,750 ‫And I'm going to show you. 56 00:03:58,750 --> 00:04:02,710 ‫So we go back to our main menu scene and in there I. 57 00:04:03,400 --> 00:04:06,880 ‫Use my main camera and I create a prefab out of it. 58 00:04:06,880 --> 00:04:10,930 ‫So I drag it into my assets, into my assets area. 59 00:04:10,930 --> 00:04:13,450 ‫And you can see my main camera is a prefab. 60 00:04:13,450 --> 00:04:16,540 ‫Now at the bottom you can see main camera dot prefab. 61 00:04:16,540 --> 00:04:21,940 ‫So that means it's a prefabricated, which we can now use in multiple, multiple ways. 62 00:04:21,940 --> 00:04:24,610 ‫For example, we could go back to our game scene. 63 00:04:26,970 --> 00:04:31,740 ‫And within our game scene we can delete the old main camera. 64 00:04:32,010 --> 00:04:38,160 ‫So now you can see display one, no cameras rendering, and we can drag our main camera inside there. 65 00:04:38,160 --> 00:04:42,180 ‫And you can see that it has all the different settings that we set up. 66 00:04:42,180 --> 00:04:44,250 ‫So 450 for the size. 67 00:04:44,280 --> 00:04:49,320 ‫It has a background which is our quad and it has a black material. 68 00:04:49,620 --> 00:04:53,430 ‫Now let's save the game scene and go back to our main menu. 69 00:04:53,520 --> 00:04:57,000 ‫Now we want to move from here to our game scene. 70 00:04:57,000 --> 00:05:00,650 ‫And in order to achieve that, we need to add some code. 71 00:05:00,660 --> 00:05:06,480 ‫So for now, our play button really just does one thing and it says play game was pressed in the debug 72 00:05:06,480 --> 00:05:13,260 ‫log, but what we need to add is our scene manager and in order to use the scene manager we need to 73 00:05:13,260 --> 00:05:14,610 ‫implement functionality. 74 00:05:14,610 --> 00:05:25,590 ‫So we add a library here which is unity engine dot scene management within this namespace scene management 75 00:05:25,590 --> 00:05:27,750 ‫that we can find the scene manager. 76 00:05:27,750 --> 00:05:30,300 ‫So now we can call the scene manager class. 77 00:05:31,650 --> 00:05:34,770 ‫Which allows us to move from one scene to another. 78 00:05:34,770 --> 00:05:41,520 ‫So we say load scene and now we can move from this scene to the next scene. 79 00:05:41,520 --> 00:05:45,140 ‫And the next scene that we want to move to is our game scene. 80 00:05:45,150 --> 00:05:47,520 ‫And here it's important to use a string. 81 00:05:47,520 --> 00:05:52,050 ‫As you can see, it expects a string as which is the scene name. 82 00:05:52,050 --> 00:05:54,840 ‫And it's important to have a scene which is called game. 83 00:05:54,840 --> 00:06:00,480 ‫Otherwise we will get an error that says no scene available with the name you entered. 84 00:06:00,780 --> 00:06:06,330 ‫So this one, the scene manager, moves us to the game scene. 85 00:06:07,980 --> 00:06:09,180 ‫So that's the idea behind it. 86 00:06:09,180 --> 00:06:14,280 ‫So I save the script, I go back to Unity, and now I start to play the game. 87 00:06:15,790 --> 00:06:17,500 ‫And I press the play button. 88 00:06:18,520 --> 00:06:19,240 ‫So that we are. 89 00:06:19,240 --> 00:06:20,230 ‫Let's press play. 90 00:06:21,690 --> 00:06:23,500 ‫And we get an error still. 91 00:06:23,520 --> 00:06:29,880 ‫It says seen game could not be loaded because it has not been added to the build settings or the asset 92 00:06:29,880 --> 00:06:31,290 ‫bundle has not been loaded. 93 00:06:31,440 --> 00:06:36,210 ‫If you ever get this error where it says could not be loaded because it has not been added to the build 94 00:06:36,210 --> 00:06:36,940 ‫setting. 95 00:06:36,960 --> 00:06:41,320 ‫You have to add it to the build setting and it's very easily done. 96 00:06:41,340 --> 00:06:54,240 ‫We go to file, then build settings or in my case on Mac, it's shift command B and then I go to the 97 00:06:54,240 --> 00:06:55,730 ‫build settings in here. 98 00:06:55,740 --> 00:07:02,970 ‫I have to add the scenes that I want to have in my build, and you can drag the scenes from your assets 99 00:07:02,970 --> 00:07:08,670 ‫folder straight in the scenes and build as soon as you've done that. 100 00:07:08,670 --> 00:07:13,200 ‫And then you can start the game and see if that works. 101 00:07:13,200 --> 00:07:17,640 ‫So I'm going to maximize and play again so that it goes it goes full screen. 102 00:07:17,910 --> 00:07:24,090 ‫And then we are I press play and I get to my black screen and my black screen is my game scene for now. 103 00:07:24,090 --> 00:07:26,280 ‫So we saw that it worked. 104 00:07:26,580 --> 00:07:29,850 ‫So play game was pressed and we were in the game scene. 105 00:07:29,940 --> 00:07:30,810 ‫Perfect. 106 00:07:31,590 --> 00:07:37,980 ‫So now you know how to create buttons, how to use buttons, how to move from scene A to scene B. 107 00:07:37,980 --> 00:07:44,370 ‫And in the next video, we are going to populate our game scene and clean that one up. 108 00:07:44,670 --> 00:07:45,060 ‫All right. 109 00:07:45,060 --> 00:07:51,120 ‫Before we do that, let's clean our assets folder because now we create folders for all the different 110 00:07:51,120 --> 00:07:54,510 ‫parts of our game in order to keep everything clean. 111 00:07:54,510 --> 00:07:59,760 ‫For now, it's not really that necessary because we only have six files or seven files, but it's going 112 00:07:59,760 --> 00:08:05,280 ‫to be much more difficult later on or much more important later on, the more complex games get and 113 00:08:05,280 --> 00:08:07,480 ‫the more different pieces you have. 114 00:08:07,500 --> 00:08:15,660 ‫So what we need to do is create a script folder, a folder for all the scripts, and I drag my play 115 00:08:15,660 --> 00:08:22,110 ‫button script in there, and then the next one is for my prefabs. 116 00:08:22,320 --> 00:08:27,420 ‫It's always important to have a prefabs prefabricated folder. 117 00:08:27,420 --> 00:08:31,950 ‫So I drag my main camera in there, then I create one for fonts 118 00:08:34,620 --> 00:08:44,430 ‫and I drag my Munroe font in there and one for materials, materials and drag my black material in there. 119 00:08:44,760 --> 00:08:50,160 ‫So as for the scenes, you can create an additional scenes folder, but what I really like to have is 120 00:08:50,160 --> 00:08:55,140 ‫my scenes at one place, which is in the root folder of assets. 121 00:08:55,950 --> 00:08:56,430 ‫Great. 122 00:08:56,430 --> 00:09:01,200 ‫So now let's save the scene, save the project, and see you in the next video.