Hello guys.
Welcome to the video.
So now that we know how camera works, I want to use it for main menu.
To make it a bit more interactive, let's go to the scene of the main menu over here.
And I want to take the tile palette and increase the level.
I want to make it longer like that.
And we need another background.
So I'm going to just duplicate it.
And let me see.
Transform.
So this one.
So this 13.5 and scale is 40.
So for this one should be 43.5.
Okay, so what I want to do is something simple.
I want character to walk here when we choose the skin, just that.
And if you want, you can then apply this technique to other UI elements.
So first we need to add a cinemachine.
Let's do Cinemachine target camera 2D camera.
And sorry, I forgot what the lens was here.
So I'm going to press Ctrl Z.
Check the lens size eight.
It was eight.
Okay, let's do cinemachine.
2D.
And lens will be eight and position should be zero zero and Z can be minus ten.
Okay, this is how it was right now.
Uh, something to do here.
We want to make an empty object.
I'm going to do as camera.
Camera target.
I'm going to call it main menu, and we want to place it at 000.
And then on the Cinemachine camera we want to assign it over here.
Like that.
So now when we go to play mode, nothing changes.
It is same as before.
This is good.
Now I want to go to.
Uh, somewhere where we can go.
How can we trigger this camera?
Let's do it from the main menu.
So I'm going to do a header here.
Header interactive camera.
We're going to need serialized field private transform.
Main menu.
Point and sterilize field.
Private transform.
Let's do skin selection point.
Okay.
Um no no no no no.
How can we do this?
Oh.
We're also going to need reference to the camera.
Serialize field.
Private Cinemachine camera.
Senior machine.
Just that.
Very cool.
I'm going to make two methods.
A very simple one.
Can I do?
Uh.
Public void.
Move camera to main menu.
This is a bit lazy approach, but I don't need a big system here.
I just want to move camera once.
If you want to have more points where your camera would move to different places in the menu, then
you could do it very simply, very easily, especially after all the things we've done.
So let's do.
Uh cinemachine.
Follow equals to main menu point.
Then we're going to need one more public void move camera to skin menu.
And over here I'm going to do Cinemachine follow equals to skin selection point.
Just that.
Just these two.
Now let's go back to unity.
Uh, we need to give it, um, camera, target, main menu.
And I want to duplicate this and move it to the right over here somewhere.
And I'm going to name it as.
Skin menu.
And we're going to go to canvas and assign it like that.
And of course we need cinemachine itself.
So let's drag it over here.
Very cool.
Now we're going to go and find a place we open in skin Selection UI.
That happens from the difficulty menu.
Yes.
Over here you're going to select these three buttons.
You're going to add event.
You're going to drag uh sorry.
We need to drag canvas.
We're going to drag canvas to for for all of the three buttons here.
And then we're going to choose.
Um.
Where is it moved?
Move camera to skin menu.
All right.
Now we have here a back button.
Do we?
We don't.
There is no back button for difficulty.
Really.
Okay.
This is interesting.
I'm going to take the back button then from somewhere.
There is a back button.
Let me just place it into difficulty.
UI remove the number one.
Yeah, this should be good.
On a back button we have go to main menu and we need to add one more canvas UI.
Move camera to main menu.
Very nice.
So now camera is supposed to move from one point to another.
Once we selected the difficulty.
Let's go and try that.
Uh, new game normal and camera.
Move to the right.
Perfect.
That's what we need now.
Actually, I was mistaken.
We need to, um.
Yeah.
Yeah, yeah.
We need to move camera back from a skin selection over here.
So I'm going to add.
Canvas UI.
Move camera to main menu.
So this is how it's going to be now.
You start the game, you go to normal mode, camera moves to the right, you can go back, camera goes
to the left.
Now what we need to do is to make this character walk into the area, and that will be very fun thing
to do.
I mean, it will.
It's going to look very nice.
I tried, uh, how can we do this?
We have menu character over here.
We can just give it a script.
Um.
Menu.
It's a shame we don't have any script on this yet.
And this one is supposed to move to the right in a very simple way.
So I think we can use move towards.
Let's do serialize field vector three.
Now let's use transform.
Private transform.
Menu.
Point and release field.
Private transform.
Skin selection.
Point.
Then we're going to need a method that would make it work.
Just want to have a boolean that says if we are moving.
So he is moving here and then update if is moving.
Then we're going to move to target destination.
I'm going to do private Vector3 destination.
And over here we're going to do vector.
Sorry transform.position equals to vector two.
Move towards from transform.position to the destination with the time the delta time multiplied by speed.
Through.
Nice field.
Private float speed.
Speed.
Over here.
Nice.
This is what we're going to do.
And then if vector two, the distance between transform.position and destination is less than.
Point one F.
Then we're going to do is moving poles.
Nice.
And there is a difference between the like the height of the position.
But we're going to fix it.
No worries.
I have an idea.
We're going to make a method public void, move to skin selection, in which we're going to pass the
Or actually we don't need these two points.
We can pass them through the method.
But did I not think of it.
Let's remove it here.
And over here we're going to do.
Yeah.
We're going to pass.
Transform.
New destination.
And then inside of a method we're going to do destination equals to new destination dot position.
And then destination dot y equals to transform position dot y.
So we don't have the difference between y position.
Then we're going to do is moving equals to true just like that.
And we're going to just type here move to.
Uh, or just move just like that.
Let's do move to move to new destination, I like it.
Now we're going to need reference to this main character.
Oh, and also we need to update is moving boolean on the animator.
So I'm going to do.
Primate animator anim.
Then awake einem equals to get component of the animator.
And then we're going to do anim set bool of is moving to boolean is moving just like that.
Very nice, that's all what we need to do.
It is very simple script.
Now let's go to the main menu.
Over here, I'm going to make a reference to the character.
Serialized field.
Private.
Menu.
Character.
Menu.
Character.
Let's save this and let's go down to the methods we have now.
Over here.
And I'm going to do menu character.
I made a mistake.
I can see that menu.
I can't rename it.
What's up man?
Let me rename it my new character here.
Okay.
Now let's go back here.
And the main character Dot move to.
And we're going to give it, um, menu point.
Over here.
We're going to do menu character move to.
Skin selection point.
Now this is supposed to work.
Let's save this.
Over here.
We're going to give it a speed maybe of.
Let's try four.
Then on the menu over here on the canvas, we're going to drag my new character to the field.
Now we can go to play mode.
Select new game and normal difficulty.
And we can see he works here so you can choose a skin for him.
This looks so funny.
I love it so much.
Um, maybe he could walk faster.
Let's give him speed of, um, ten and let's click back.
Yeah.
Okay.
So he works better, I like it.
We only need to.
Lithium, right?
Uh, how can we flip him?
Well.
We could decide instead of a move method, how do we flip him?
But I feel a bit lazy.
So I'm going to go to player script.
I'm going to find that.
Leap methods I have.
Over here I'm going to copy them.
Go to Menu Character, paste them in.
Then we're gonna.
Generate field for facing direction and generate field for the facing.
Right now we need to fix it because this one was used as an object.
We need a boolean here.
Just like that.
Okay.
And then we go back here.
Instead of X input we're going to pass float x value.
I'm going to type x input.
And then I'm going to rename it to x value.
And then instead of zero, we're going to use.
Transform position dot x.
And here transform position dot x.
And then when we do move two we're going to do handle flip according to the destination dot x.
Just like that.
Now character is going to flip if he needs to.
Let's go back.
I'm going to increase the speed by default.
Let me try eight.
And let's see this.
Let's go to play mode.
Can I do a new game and normal mode?
Why?
He does that?
I don't know why he does.
Wait.
What if we go back?
Okay.
This is funny.
I guess we need to do facing direction equals to one by default and facing right?
True by default.
Let's save this and let's try once again.
If you want, you can place your character somewhere to the right over here and make him look left by
default.
Then he would just turn back when he needs to change the skin.
Uh, you could create another position for it, and you could even do this for all of the menus we have
with different positions that could work as well.
Let's go.
New game.
Normal.
Walks up.
I can change skin for him and I can even go back and he's going to go back with a new skin.
Oh, man, this is so cool.
Yeah, and even you can change skins while he is walking because we use animation layers.
And the issue is you can make him walk away with this skin.
But I don't think it's important because you did not select it, so it's not selected.
And if you click continue, you're going to just, uh, play with the skin you had before, right?
By the way, let's check this.
And now let's go back and let's continue.
I'm going to have the default one.
Okay.
Very very good.
Do we save in this info about the skin?
I completely forgot.
Let's just make sure of that.
Let's go to game manager.
Over here somewhere.
We update info about last like continue button.
Here we save and continue button.
Let's save the skin index as well.
Let's do Playerprefs.
Set int of.
Last I used skin.
I'm going to give it a index of a skin skin manager dot instance dot skin, get skin ID and then we
need to load it only if we press continue button.
That happens in the UI.
Let me copy this.
UI.
Um.
Main menu.
We have continue game.
So just before I do that I'm going to do skin manager instance, set skin ID to the playerprefs.
Get integer of.
Get integer of the saved value.
Okay, so last used last saved screen equals to.
And we're going to use it here.
Last saved skin.
So now continue button will use skin as well because I've like I missed that I missed that part.
Let me try it.
Going to go to play mode.
New game normal.
Going to select the frog.
Select the last level.
Now we are on the new level.
Gonna go out of a play mode.
It's going to go to play mode.
Click continue.
And with the frog okay, cool.
Let's go to the next video.