Hello guys.
Welcome to the video.
So we already have a main menu scene.
We have the game scene.
And in this one I want to show you how to make the end scene.
It's going to be very simple one.
We're just going to show some credits.
We're going to roll the text and that's it.
It's going to be simple but effective.
And if you want to add some more graphics there you can easily do that, especially once we're done
with the UI section.
You're going to know enough information to do any upgrades that you want to have.
So as of now let's start with simple.
Let's make a prefab for this background so we can use it in another scene.
Uh we're just going to go to prefabs drag it here like so.
Now you can see that this background says none in the material.
And if you drag it to the scene again it's going to be purple like that.
So what we need to do is to select the background, lock it, go to Asset Materials and drag this background
material here.
Just like that.
Nice.
Now we can unlock it.
And every time you use a background it's going to have this yellow background by default.
And then if you want to change it you can choose color and click Update Background.
And it's going to change it okay.
Um, yeah.
There is also an error with the material over here.
We can easily fix it, but actually it's not that important I guess.
But if you want to fix it, just do mesh shared material, dot main texture and we're going to save
it.
Now we can go back.
And if you change color to something else, let's say blue and update again, we'll be fine.
Okay, now let's delete it from here.
And let's go to asset scenes and let's make a new scene.
Uh, going to be seen.
Seen the end?
Just like that.
Now we can go inside of this scene.
Let's save it.
We can go to asset prefabs.
Let's take a background, drag it in the middle like so.
I want to have green color.
So I'm going to do green update.
And I want this background to be a little bit darker and also further away.
So I'm going to go to main camera, choose size 7.5.
And I'm going to go to background itself and click.
2D sprite square.
So now it will take entire space of the object.
And over here we can just choose black color and make it transparent to something like 40.
So it's a bit darker than usually we have.
Now let's go and make a canvas.
UI.
Canvas.
And inside of this canvas, I want to make an empty object and I'm going to call credits.
Inside of the credits, we're going to make UI text, mesh Pro text, and this text will say anything
that you want.
Uh, for example, let's go and do Minecraft as the font first, and let's try to increase the size.
I'm going to try 60 by 100, and we need to align text in the center.
And this text definitely could be bigger.
So I'm going to increase size to something like.
This and I'm going to write here D.
And just like that.
Now I want to have another text element.
So let's add one more and we're going to just take it, move it down and change text to something else
created by Alex, something like that.
I think I'm going to stretch the text box or actually let's take the element and stretch the entire
element.
From this one font could be smaller.
So I'm going to reduce font size to something like 60.
And we can make another element, drag it down and write something else.
Uh, for example.
Visit unity.
Alex Dave.com.
Yeah, I have a website.
I can put a website here.
Why not?
And now there is something else I want to tell you.
As of now, you can see.
Actually, let me make one more.
I'm going to write something like thank you.
And yeah this is good for elements.
Should be okay.
Now wait a second.
I want to write something else to learn how to make games.
All right.
This is good I like it.
And then I'm going to put one more, drag it down and say thank you.
All right.
So you probably noticed how irritating it was to move object down every time we create a new one.
Plus to that, they have an even space between them.
And I really need to check the space between them to align them properly.
And I don't want to do that manually.
That takes lots of time and energy.
Luckily for us, unity has a component that will do it for us.
Let's go to credits and let's make I mean add component vertical layout group.
Let's click enter.
And now you'll see all of the elements are aligned automatically.
We only need to change child alignment from upper left to middle center.
And if you want to have more space in between them, you can increase spacing value over here.
Uh, for example, let's do.
60.
Okay, this looks good to me.
Now let's go ahead and we're going to talk about similar components later on.
Once we create level selection they're going to be layout group.
And I'm going to talk more on how to use them.
As of now let's just do simple setup like you see on the screen.
Now let's go ahead and align the credits element to the bottom middle like that.
And I'm going to move it a little bit below.
All right this is good.
Now we need a script that will move this text up.
I'm going to go to Asset Scripts and let's make a new Monobehaviour script.
Hey where is it.
Come on.
Yeah.
UI credits.
Very good.
Now we're going to find the script UI credits.
And over here we need to do something simple.
We're going to need.
Um.
Let's do.
Generalize field private rect transform.
I'm going to name it as just rect t, and then I'm going to have serialized field private float speed.
And let's make it as 200 by default.
Then we're going to open up the gate.
And in the update we're going to do react to.
Dot anchored position plus equals.
And we need a value to move this object up.
So we're going to do vector two dot up multiply by speed.
Maybe let's change it to a scroll speed.
Yeah.
And multiply by time dot delta time.
Very nice.
Now I'm going to save it.
And let's go back to unity.
Drag this on the object.
And let's assign React Transform over here and go to play mode.
And you can see when we start in the scene, we have credits.
Very cool, I like it.
Very nice.
Now let's go ahead and save the scene.
And then we're going to go and enable this scene when we reach in the final point on the level.
Uh, before that, we need to go to File build profiles.
Here we have scene list.
And over here we need to add all of the scenes we used in the project.
So let's go to asset scene.
Let's choose main Scene and place it over here at first.
So this is going to be run first if you build the project and then the end over here.
So now they are in a scene build and they can be used.
Next step would be to close this window.
Let's go to, um, sample scene or I'm sorry, sample scene.
And we need method on the game manager that we can call from the finish point.
Let's go to game Manager somewhere below.
I'm going to make a method.
Public void.
Um, load the end scene and it will do something simple.
Scene manager load the scene with the name D, and that's the name we have in the asset folder.
Okay, this is good.
Now let's go to finish point.
And over here I'm going to just do Game Manager dot instance.
I'll load the end scene just like that.
Now it's going to load the scene immediately.
And I would like to do it with a delay, but I'm going to show you how to load it with a delay in the
next video once we make fade in and fade out effect.
All right.
As of now, let's just load it immediately.
Let's go back to.
Unity.
And I'm going to go to asset scenes main menu.
And I'm going to run entire sequence from start to finish.
Let's go new game.
We are here.
Then I'm going to jump into this, uh, finish point and game is finished and we have the end message.
Cool.
Now I want to be able to skip this scene and jump back to main menu once I've seen them or something
like that.
We can do that easily by going to.
The end over here.
And let's make a button, an invisible button.
We're going to make a UI button.
Text mesh Pro we're going to stretch it.
Like that.
Then we're going to remove text from here.
And we're going to make it transparent, but it will be clickable and we just need the event.
Uh, that would run the main menu scene if we want to.
Or speed up the text, and then it would go to main menu.
How can we do this?
Uh, first.
Maybe.
Maybe we can take this component.
Let's take it.
Paste this component into canvas as new and I'm going to remove it from credits over here.
And we can write all the functionality for this scene in one script.
I'm going to do.
Uh.
Private void skip credits.
And I want to make a boolean that says if credits are skipped and bill credits are skipped.
Then we're going to do this.
If ready skipped are false, then we're going to just do scroll speed equals to um 2000.
Or basically let's just multiply it by ten.
Uh, multiply by ten and we're going to do credit skipped equals to true and then else.
So if credits are skipped then we're going to just do scene manager load scene of the main menu.
Okay.
Uh, for this.
Maybe just in case, let's make, uh, serialize field Privatestring.
Main menu.
Scene name.
I'm going to make it equals to main menu by default, but you can change it later on.
And I'm going to use here.
Main menu.
Scene name.
Very nice.
Now let's go back.
Let's select this button.
Let's add event.
Drag the canvas over here.
Find UI credits.
And that method is private, so we cannot see it.
Let's go back and make it public.
Public.
I'm going to save it.
Go back.
And.
Oh, I'm sorry.
We need canvas here.
UI credits.
Skip.
Credits.
Okay.
Let's try.
Nice works very well.
I like it and we can start the game again.
What we could do now is to check if text went off the screen, and if that happened, we can go to main
menu automatically.
Let's just take the credits and move them up till the text leaving the screen.
So for example here and we can see the position is 1784.
Okay.
Let it be 1800.
So when position will be equals to that or bigger than that, we can go to main menu.
Let's go to script.
First, I want to take this into a method.
Extract method.
Go to main menu.
Then we're going to go back here and make a serialized field, private float off screen.
Uh, position.
Maybe.
Let's make it equals to 1800 by default.
Then in the update I'm going to do if rect t anchored position dot y is bigger than offset screen position,
then go to main menu.
Now let's save this.
Let's go back and see it.
I'm not going to touch anything.
I'm not going to click any buttons.
I'm just going to take this text and bring it back here.
Okay.
Let's go.
So it is moving, not clicking anything.
And we went to a new game.
Very nice.
Works very well for us.
Now let's save everything and let's go to the next video.
We're going to make fade in and fade out effect.