And this exit button.
So basically what we're gonna do, we're gonna use the scene management script, which we created earlier.
So make sure you just move over to your levels in basically the sample scene.
So firstly we will head over to Project App Assets and then since folder.
And let's double click on this sample scene in order to move over to that scene or level and make sure
you just go over to hierarchy and select your scene Management game object, and then turn it into a
prefab so you will have the copy as well as we're gonna have this scene management script, since we're
gonna do it inside this scene management script.
So basically that is the thing.
And once we just made it prefab, then we can just move over to our scene.
So let's double click on on it.
This scene or what.
Simply you can do you can select any GameObject in the hierarchy.
And you can select the Scene Manager script and then drag it over to that GameObject.
And after that you can just do the scripting.
So basically the same thing.
Uh, but I already have the sim management game object, so I'm gonna drag my sim management game object
in the hierarchy inside my nano sim.
To do so, let's head over to Project Assets and then prefabs folder, and I'm gonna select this scene
Management game object from this inside this prefabs folder.
And let's drag it over to hierarchy or into this scene view.
So I'm going to drag it over to my hierarchy.
And now what we need to do.
We need to hook this play button with this scene management uh script.
Basically we're going to create a function for this play uh play button.
So whenever we're going to click on this play button, then we just want to play our game.
So we're gonna make a function for our play button as well as for this exit button to do some, uh,
things like once we're gonna click on this play button, then we want to play our game.
And once we click on this exit button, then we want to exit our application or the game?
So let's open up our scene management script by double clicking on it.
And let's make two function.
So I'm going to move over to top of my class.
And you can do it anywhere.
It doesn't need to be in order.
And make sure you make this function public.
So we can call this function through our button.
So firstly I'm going to create a function for my play button.
So let's make public uh public.
So make sure you make it public so we can call the function on click.
So whenever we're going to click on that play button then we want to call the function.
So that's why we're just marking this function as public.
And for function we're going to type void.
And we have to name the function.
So I'm going to call it play uh game something like that.
Let's make first bracket and some curly brackets.
And whenever you're working with scene.
So make sure you just go to top of your class and include this namespace called using Unityengine Scene
management.
So make sure that is it.
a basically, it exists in our script already, so make sure you just include that.
Uh, so what we want to do inside this play game function, we want to play our game.
So we need to load up our sample scene or the level scene.
So we're going to use this scene manager uh scene manager dot load scene function dot load scene function.
And this function in brackets.
It's going to take the scene and name scene name in quotation.
Or you can simply, uh, basically pass the bill index of it.
So if we move over to unity and go, uh, and move over to hierarchy, we can see the name of the scene
is a Manu.
And if we move over to our project tab assets and then prefabs folder.
Sorry.
Uh, since folder we can see the sample scene right over here we have is the level scene.
Basically we're just playing our game inside this sample scene.
So if I just double click on it.
So I'm going to click on this save button.
So whatever I have done inside this magazine, it's going to be safe.
So I'm going to click on this button.
And as soon as we click on that save button, we can we just move it over to our sample scene or the
low level so we can see the name of the scene in hierarchy right over here in the top.
And the name of the scene is sample scene or what else you can do.
You can see the name as well in your build profile.
For that, you basically need to move over to the top left file, then click.
Then click on this build profiles in the bottom and you can see the name of the scene.
So you will be scene list.
Labs are basically left side.
We can see windows and it says active.
And we're going to click on this open scene list.
And we can see the name of the scene is Sample Scene.
But we don't have the scene inside our scene list.
So we're going to drag that.
So going to select our scene that scene from that scenes folder.
And let's drag it over to this scenes list.
And we're going to drag this piano scene in the top, because this one should be the default one.
So whenever our player just gonna open our game, this menu should load up right away or so.
That's why we just drag it in the top.
And now we can see the name of the scene is Sample scene and the build index.
We can notice in the right section which is one.
So we can simply pass the build index of it.
Or we can simply pass the name of the scene which is sample scene in quotation.
So it's basically up to you what you want to do.
So I'm going to cut this tab by now.
Let's move over to our script.
And over here it's going to take the name of the scene.
So we can pass in quotation the name of the scene which is sample scene.
Or you can just, uh, what you can what else you can do.
You can just remove this, uh, name of the scene or, and you can simply pass the bill index of it,
which is one, and make sure you just close that off with semicolon.
But instead of passing the name of the, uh, sorry, build index of it.
I'm going to pass the name of the scene.
It doesn't need to be, but it's basically up to you what you want to do.
So make sure you type quotation first and then pass the name of the scene, which is sample scene and
make sure you spelling it correct, else it's not going to work at all.
So I'm going to press control S on my keyboard in order to save my script.
And now let's move over to unity.
So firstly we need to move over to scene.
And we need to hook that play button play button with our play game function.
So just wait a moment and once our compilation is done, we can just go ahead and we can do that thing
in order.
A basically we can do that thing.
So just wait a moment.
Uh, firstly, we are just going to move over to our panel scene and we're going to hook that play button
with our play game function.
So just wait a moment.
So now I'm gonna double click on this scene.
Firstly, I'm gonna move over to my project tab assets and then scenes folder.
And let's double click on this scene and move over to inside basically and move over to this panel scene.
And now what we're gonna do, we're gonna move over to Hierarchy Canvas, and then we're going to select
our main panel.
And let's select this BG.
And then we're gonna select our play button.
And if we go over to Inspector then scroll to down to the button component.
We can call the function over here.
So let's click on this plus icon.
And we need to drag the GameObject in which GameObject the script is sitting on.
So if I move over to hierarchy, the script is sitting on inside the Scene Management GameObject.
As you can notice in Inspector.
So I'm gonna select my play button.
And then we're gonna scroll down to the button component.
And we need to drag the GameObject in which GameObject the script is attached, in which GameObject
the script is already attached.
So in my case Scene management.
So I'm gonna drag that into that slot and it says no function.
So let's click on it.
And then we can see in the bottom we have the scene management script or scene management C-sharp class.
And inside that scene management script we created the play game function.
And we can notice right over here.
So we're going to choose that.
So now as soon as we're going to click on this play button that function just gonna trigger.
And what this function is really doing it's just loading up the scene, which is uh, we can see the
name of the scene inside quotation, which is sample scene.
Or you can simply pass the build index of it.
And now what we're going to do, let's click on this play button in the top in order to test it.
So whenever we click on this play button you will be able to notice that we're just gonna move over
to sample scene or in which scene we just playing our game.
So just wait a moment.
And if I just click on this play button, uh play button.
So just wait a moment.
So as you can see, as soon as we clicked on that play button, We just move it over to our sample scene.
And you can notice in your hierarchy tab.
So if we move over to hierarchy tab we can see the name of the scene is Sample scene.
And if we try something like this uh, we get a pop up.
Sorry.
We're gonna get a pop up.
Uh, I don't know what's happening, so we cannot say.
Just wait a moment.
So let's leave it for that.
And now let's talk about this exit button, and we're gonna talk a we're gonna take a look on that back
later.
So, uh, wait for some moments and we're going to do that.
Uh, so what we're going to do now, we're gonna talk about this exit button.
So we need to hook this exit button with our exit function.
To do so, we're going to move over to our script and let's make a exit a game function for our exit
button.
And I'm going to do it in the bottom.
It doesn't need to be in order as well.
Uh, like I have, uh, I have already told multiple times, and I really apologize for it.
So for function we're going to type, uh, so for for function we're going to type void and make sure
you make this function, uh public as well.
And we're going to call this function to something like exit game.
Let's make first bracket and some curly brackets.
And we do know that, uh, we in order to quit our application we need to use this application.
So we need to use this function.
It's called application.
Application.
Sorry.
It's application dot quit function.
Quit function.
And then make this first bracket and then close that up with semicolon.
And we do know that uh, in unity editor, it's not going to exit or quit our application or the game.
But we do know that once we're going to make the game completely, and then if we click on this exit
button, then it's gonna quit our game right away.
So in order to test, uh, purposes, we're gonna print out a message.
So if we click on this exit button, we're going to say something like exit.
And we just.
And make sure you put this line of code which is application dot quit in order to quit your application.
And in unity editor, it's not going to happen at all.
So for testing purposes, uh, basically to check that exit game exit button is working or not, we're
going to print out a message.
So for printing out we're going to type this debug.log and we're going to say something like exit game
in quotation.
So let's say exit game.
And then let's close that up with semicolon.
And we're going to press down.
Really sorry I really apologize for this.
And we're gonna press Ctrl s to save our script.
And now let's move over to Unity editor.
So we need to hook this exit button with our exit exit function.
Exit game function, and we do know what we're doing inside that function.
We basically printing out the message says exit game.
So we need to hook this exit button with our exit function.
So I'm gonna choose my exit button.
Uh underneath my BG, inside this main menu, underneath my canvas in the hierarchy.
Let's go over to Inspector and scroll down to the button component.
And we can call the function over here.
So let's click on this plus icon in order to call the function.
And we need to drag the game object in which game object the script is sitting on.
So we're going to select our scene management.
Let's drag it there and it says no function.
So let's click on it.
Let's go over to scene management.
And we're gonna choose our exit game function for this exit button as you can notice.
So whenever we click on this exit exit button then exit game function just gonna call out.
And we do know what we're doing inside that function.
So let's click on this play button in the top.
And I'm going to select my console tab in order to check that out.
So just wait a moment and once we are done we can check that out.
So just wait a moment.
So now if we just select our console tab and then click on this exit button.
As you can see, as soon as we're clicking on that exit button, the message just getting pop up in
our console tab says Exit Game.
But we can notice that we are not quitting our game at all in unity Editor or we not exiting out from
this, uh, game.
So basically that is the thing.
And once you make the application completely basically your game, and then if you just go ahead and
then click on this exit button, then it's gonna quit your application or the game right away.
Uh, or it's gonna exit your game right away.
So I hope you get the idea.
And if we click on this about panel, we just moving over to about menu section.
And if we click on this back button we can notice we can just moving over to our main panel.
And if we click on this play button then we just playing our game.
So basically we just loading the samples in and we're gonna take a look on that back later.
So let's take a look on this now.
So it's basically working fine.
So it's fine.
So I'm gonna get out of play mode.
And we're gonna talk about the bug later.
So I hope you get the idea that how you can make it.
And now we're going to press control S to save our project.
But before you do, make sure you select your main menu.
Basically the changes we have done inside this main menu.
So make sure you select that.
Then go over to Inspector, then over it and then apply all.
So the changes we made over here, it's going to be saved into this main banner prefab game object as
well.
Or copy of this main panel UI or this main panel game object.