We need to hook this button with some certain function.
So we will use the scene management script as we created before.
But before we do, let's move over to this sample scene by double clicking on it.
Because we have the Scene Management GameObject underneath our uh, sample scene, we can see in the
hierarchy.
So we need to make this one prefab.
So we're going to have the copy.
And then we can use uh because we have this scene management script is attached to scene management
game object as you can see in the inspector.
So we will make this one prefab.
And then we're going to use it in our scene as well.
So we're going to use the scene management script one more time.
So we don't need to create another script to manage the scene.
So let's select the Scene Management GameObject in the hierarchy, and let's drag it over to this prefabs
folder in order to make it prefab.
And now we're gonna move over to our scene.
So let's head over to this scenes folder.
Let's double click on this scene and we will click on this save button.
Uh, so basically, whatever changes we made inside this sample scene, it's going to be saved.
And I really want to save that.
So that's why I'm going to click on this save.
And as soon as we click save we can see we just moved over to this scene.
And now I'm gonna move over to my project tab assets and then prefabs folder one more time.
And I have the scene Management game object over here.
So let's select that game object or that prefab of that scene management game object.
And we will drag it in this hierarchy in order to use it one more time.
And we can see we have the scene Management GameObject in the hierarchy.
And inside this scene management game object, we can see we have the scene management script.
So let's open that scene management script.
But before we do let me explain.
So once we click on this play button we want to play our game.
And once we click on this abort button then we just want to move over to about a menu.
And once we click on this exit button then we're going to quit our application or the game.
We just want to exit.
So let's double, double click on this scene management script and we will make, uh, more function
one for our, uh, play button and one for our exit button.
And we will talk about that about button later on.
And I'm gonna move over to my top of our class, and we will make the function over here, and we will
make that function public because we're going to call this function uh, from click event means whenever
we're going to click on that play button.
And then we will call the play function.
So let's make a function of for our play button.
And let's make that one public.
For function we will type for it.
And we have to name the function.
I'm going to say something like play game and let's make first bracket and some curly brackets.
And what we want to do inside this function, we just really want to load up the scene, uh, load up
the scene or the sample scene or which scene we are playing our game.
So we will use this in manager dot load scene function in order to load up the scene and make sure you
just go to top of your class before you use this function, include this namespace called using Unity
Engine dot Scene Management.
It's going to allow us, in order to use this scene manager dot seed function in order to load our scene.
And inside this load scene in this brackets, we need to pass in quotation the name of the scene, or
you can simply pass the bill index of it.
So, uh, in this play game function, we just load up the scene that in which scene we are playing
our game.
And we do know the name of the scene is sample scene, in which scene we just playing our game.
And if you just want to take a look of it then just move over to unity.
In the top left you can see file.
So just click there and then click on this Build Profiles.
And you can see the name of the scene over here.
And uh so basically you will be in windows.
Then click on this open scene list over here, and as soon as we click, we can see the name of the
scene is a left side, which is sample scene and the build index.
We can see in the right side which is zero.
So we can simply pass the build index of this scene as well as name of the scene.
So I'm going to pass my name of the scene which is sample scene or in which scene you were playing our
game.
Or you can check that by going over to this project tab, then assets and then since folder or where
you have the scene.
So if I just double click on this sample scene, we can see in this sample scene we are playing our
game.
And you can take a look on that as well.
By moving over to this hierarchy.
And in hierarchy you can see the name of the scene is Sample Scene.
So I'm going to move over to my scene once again.
So the name of the scene in quotation we're going to pass.
So the name of the scene is sample scene.
So let's pass name of the scene.
So in our case sample scene sample scene.
And let's close that up semicolon.
Or you can simply pass without coercion the index of it.
So the build index was zero.
So you can pass the build index as well.
But I'm not gonna do that.
And let's press down Ctrl s to save our script.
And let's move over to unity.
And we will choose our play button.
So whenever I am gonna click on this play button then I will call that play game function.
And what that play game function is doing.
It's basically loading up the scene in which scene we are playing our game.
So just let's have a look on this.
So just wait for to compile our script.
And once it's done we are ready to do that.
So let's go over to this hierarchy then canvas and we will move over to mano.
And then let's choose this play button.
So let's choose the play button underneath your menu GameObject in the hierarchy.
Then go over to Inspector, scroll down to this button component and we can see on click and it says
list is empty.
So over here we can call the function.
And in order to call the function we need to click on this plus icon.
And over here we need to drag the game object in which game object the script is sitting on or attached.
So in our case this scene management game object the scene management script is attached.
So we will select our scene managed game Management game object in the hierarchy.
And let's drag it over to that slot.
And it says no function.
So just click there and we do no inside the scene Management game object.
The scene management script is attached.
And we can see in the bottom which is scene management script.
So we're just moving over to this scene management class.
And over there we.
We can see we just created the play game function.
So we're going to choose this play game function means whenever we're going to click on this play button.
And the this uh we just moving over to scene management game object first.
And then from this scene management game object, we're just going over to the scene management script.
And from this scene management script class we're calling the play game function.
And what play game function is doing it.
just loading up the scene in which scene we're playing our game and we can see the name of the scene
is Sample Scene.
So let's move to unity.
And now let's click on this play button in the top.
You will see as soon as we're going to click on this play button, the sample scene just gonna load
up the or the scene in which scene which is playing our game.
And you can rename the scene as well.
So if I just click on this play button and as soon as we click on play button, we can see we just loaded
loaded up the sample, uh sorry, sample scene or which scene we just playing our game.
And if I just click on this menu button, we're not loading over or we're not getting over to Manos
in yet.
Basically once we click on this menu button, then we need to load up the scene as well.
But we're going to take a look on that later.
Let's get out of play mode.
And let's uh, let's deal with this exit button now.
So we will make a exit for uh, exit function for this exit button.
So let's move over to script and I'm going to make it in the bottom.
You can make it anywhere.
It doesn't need to be in order.
So we're going to make a public void.
And let's call this function something like exit game.
Exit game.
Let's make first packet and some curly brackets.
So inside this function what we're going to do we will use this application dot quit function.
So make sure you just are doing as I did over here.
Then close that up with semicolon.
So what this function is just going to do.
It's going to quit your application right away.
But in unity editor it's not going to happen.
It's not going to quit your application at all.
But once you make the build or the game completely, then you just go ahead and then click on this exit
button.
Then it's gonna quit your application or the game, but it's not going to happen in unity editor.
So if this function is perfectly working or not, we're going to check.
So in order to check before we quit we're going to use this debug dot log function in order to print
out the message in the console, and I'm going to say something like exit.
Uh, so I just printing out this message, uh, for testing purposes, if it's perfectly working or
not or correctly working or not.
And let's close that up with semicolon.
But it's not going to quit our application in unity editor.
But once we meet our game totally or completely, then if we just click on that exit button, then it's
gonna quit our application or the game and let's press down Ctrl S to save our script and let's move
to unity.
So we need to choose our exit game function for this exit button.
So whenever we're gonna click on this exit button and that exit game function just gonna call.
And we don't know what we have done inside that button.
We just quitting our application.
So let's go to Nano Game Object and let's choose the exit button.
Let's go to Inspector.
Scroll down to this button component and let's click on this plus icon.
So we need to drag the game object in which game object the script is sitting on.
So the script is sitting on this scene management.
So we're going to drag right there.
Let's click on this no function.
Let's go to scene Management Script or Scene Management C class.
And we're going to choose this exit game function for this exit button.
And now let's click on this play button in the top.
Uh in the top.
And we will choose our console because we just printing out message and we want to see our message underneath
our console tab.
So let's uh select the console.
And if I just go ahead and then click on this exit button.
As you can see as soon as we're clicking the message in the console says exit because that exit game
function is just calling.
And what exit function is just doing its exit game function, it just printing out the message in the
console exit.
And after that it's just coding our application.
And we can see that we're not quitting our application at all in unity editor.
But you once you make the game completely or the build, then you can just go, go ahead and it's gonna
quit your application right away once you click on this exit button.
So now let's head, uh, let's talk about our mano button now.
So let's get out of play mode and let's go to our project tab then since, uh sorry, this assets folder.
And let's move over to these scenes now.
And let's double click on the sample scene and let's click on this shape.
Uh, so what we need to do we need to once we dying and clicking on that menu button, we can see with
that we have seen that we not moving over to mano scene.
So once we click on that mano button, we just want to load up the mano scene.
So we need to and we just printing out the message in the console says mano.
So let me show you, if I just click on this play button and then this player game object just loses
all of his self, you will see the game over you by just going to be activate.
And once we click on that mano we're not loading up the menu as at all.
So let's have a look on that.
Let's take damage from this enemy game object.
And if I just click on this menu button by now we can see a we just printing out a message in the console
says load menu.
And instead of printing out message we really want to load up the menu instead of printing out message.
So let's get out of play mode.
And before you load up the menu scene, make sure you just go to top left file and then build profiles
in the bottom.
And then click on this open scene list and move over to the scene list.
And over here what you need to do.
You need to drag all of the scenes that you have.
So we want to load up the menu scene and we can not able to see our scene in this scene list.
So what we have to do, we need to drag our menu scene into this list.
So we will move over to our project tab, then assets and then since folder.
Because in that since since folder, we just created our scene and we can see it over here.
So what we need to do, we need to select our scene, then drag it over to this scene list in this,
uh, over here, in this scene list, make sure all of the scenes are in this inside this scene.
If it's not, then select them and drag it over here.
And I'm going to drag this scene in the top.
Why?
Because I want this scene to be the default one.
Or once our play player games.
Uh, player just start our game.
I want this menu to be the default one.
So that's why I just drag it, this menu in the top, and then these samples in the down.
And by now we have both of this scene.
We have this menu as well as as well as we have the sample scene.
So let's get the cut this tab and let's uh move over to our menu function where we just printing out
message.
So in our case we're doing inside this scene management script.
So we're going to select our Scene Management GameObject object in the hierarchy.
And let's open up the scene management script by double clicking on it.
And we can see over here we're just printing printing out in the printing out the message in the console
says load menu.
And you can notice over here and after printing out message we also want to load up the menu scene.
So what we need to do we need to use this scene manager function in order to load that up.
So we're going to use this scene manager dot load scene.
And we do know this over here load scene.
It's going to take the scene name in quotation or the build index of it.
And if you just want to see that then move over to unity.
Go to top left file, then build profiles and then scene list so we can see the name of the scene is
nano and the build index of it we can see in the right which is zero.
So we can simply pass the build index as well as the menu.
So I'm going to pass the name of the scene instead of the build index, and make sure the scene is in
this scene inside the scene list.
If it's not then drag them as we have done.
So I'm going to cut this step by now.
Let's go to script.
And in we're going to make a quotation.
And let's pass the name of the scene.
Or you can simply pass the index which is zero.
And let's close that up with semicolon.
But instead of passing bill index I'm going to pass the scene name.
So I'm going to do inside this quotation.
So the name of the scene is mano.
And let's press down Ctrl S to save our script.
And let's move to unity by now.
And let's have a look on this.
So just wait for to compile.
And once it's done we are ready to do that.
So I'm going to clear my console.
Let's click on this play button in the top and have a look on it.
How about.
It.
So just wait.
We're going to take damage.
So let's take damage.
And now if I just go ahead and then click on this menu button.
And as soon as we click on that menu button, we can see we just headed over to our mano scene.
And we can just click on this play button in order to play our game.
And we can take a look on on this once again.
So let's have a look on it.
So I'm going to take damage.
And let's click on this menu button.
And as soon as we click on that menu button we just head it over to our mano scene once again.
So this is the cool thing.
I hope you get the idea.
And now let's talk about our about button.
So I'm gonna get out of play mode and let's head over to our scenes are seen in order to do that.
So I'm going to move over to my move over to my project tab and then assets and then scenes folder.
And let's double click on this mano scene in order to move over to that scene.
And let's talk about this about button.
So I'm going to move over to my hierarchy then canvas.
And let's select this mano and then this about button.
So once we click on this about button then I just want to disable this menu UI.
And I want to activate this about menu about menu UI.
So once we click on this about button.
So we will choose our about button underneath our menu GameObject in the hierarchy.
Let's go to Inspector.
Scroll down to this button component.
And we can just click on this plus icon in order to do a action.
And the action I want to do.
Basically, I just want to deactivate this menu itself, and I want to activate this menu about menu.
And once I click on this about button.
So you need to drag the game object.
Which game object just you want to activate or deactivate.
So in my case I just want to deactivate this menu.
So I'm going to select my menu Game Object itself.
And let's drag it over to that slot.
And it says no function.
So just click there.
And over here you can see game object.
So game object basically just referencing itself hole.
And we will choose the bottom in the we can see said active and it says bull.
So if you just take their check, check basically means you just enabling it.
But I want to disable this menu once I click on this about button.
So I'm gonna disable.
To disable we just have to uncheck and we're going to click on this plus icon because we're going to
do one more action.
And the action I wanted to I want to I want basically to do is that we want to activate our about menu.
Once we click on this about button about button, then I want to disable the menu and I want to activate
the about menu.
So over here over here we need to drag the game object or which game object just you want to activate
as a second parameter.
So as a second thing.
So we're going to activate our about menu.
So we will select our about menu game object.
And let's drag it into that slot.
And we will click on this no function.
We will go to game object basically means it just referencing itself.
And we're going to use this set active bool function in the bottom and we're going to check it.
Check.
It basically means we're just activating that and let's have a look on it.
So basically whenever we're going to click on this about button at the menu just gonna be deactivate.
Basically gonna disable.
And that's why we just leave it unchecked.
And we just activating this about menu means about menu.
Just gonna be activate as soon as we click on this about button.
So let's have a look on it.
So I'm going to click on this play button in order to play our game.
And we're going to take a look on it.
So as soon as we're going to click on this about button you will see this menu just gonna be deactivate.
And that about menu just gonna be activate right away.
So let's have a look.
So if I just click on this about button, as you can see, as soon as we click about button we can see
this about menu just gets activate.
And that menu uh about about menu you may just get deactivate.
And we can see underneath our canvas GameObject in the hierarchy as well.
So the menu we can see, it just gets unchecked in the inspector.
And this about button.
About menu just gets a check in inspector means we just activating.
And once we click on this back button then what I want to do I want to activate one more time the menu.
And I just want to deactivate this about menu.
So let's get out of play mode.
And now we're going to choose our back button.
So whenever we're going to click on that button then back button and back button, then we're going
to do all of those stuff.
So let's move over to this about menu by now.
And let's select the back button inside this about menu.
So let's select the back button.
Go over to Inspector.
Scroll down to Button Component and we're going to click on this plus icon.
So we need to drag the game object which which game object we want to activate or deactivate.
So in my case I'm going to select my menu.
And let's drag it right there.
And we will go to no function then Game Object.
And we're going to use this set act set bool.
And I'm going to check this because I just want to, uh, activate this about a new UI.
Once we click on that back button.
And after that, I want to deactivate the about menu.
So we're going to click on this plus icon one more time.
And we can just drag the game object which game object we want to disable or enable.
So I'm going to select my about menu itself.
Let's select that and drag it over to this slot.
And we're going to click on this no function game object and set active.
And I'm going to uncheck means we just disabling or disabling our about menu.
As soon as we click on that back button and we're just enabling our menu UI.
You can see in the inspector on click event as you can see.
So I hope you get the idea of this.
And let's uh, let's test it.
So I'm going to click on this play button to play our game.
And we will test uh about this about button.
So as soon as we're going to click on this about button you will see the menu UI.
Just gonna be uh disable.
And the about menu is just going to be activate.
So let's click on this about button.
and we can see as soon as we click on that about button, we can see that this about menu just gets
activate and that menu UI just gets deactivate.
And now if I just click on this back button and we can see as soon as we click on that back button,
we, we can see that this menu just gets activate.
And that about menu gets deactivate or disable.
So basically that this is the thing that how you can use a button to do specific things or the things
that you really want to do.
A this is a pretty short way to do, and this seems pretty much cool to do it.
I hope you get the idea that how you can do so I'm going to get out of play mode and let's select the
parent game object.
Let's go to overrides Apply all, and I'm going to do the same thing over with this about menu game
object as well.
Let's go to overrides apply all.
And now it's saved.
And I'm going to press down Ctrl s on my keyboard in order to save my project.