So if we just go ahead and then click on this play button and you will notice as soon as we're going
to right click that, uh, that uh, vector UI just gonna pop up.
So just wait a little moment.
And we don't want to do that when once we click a right mouse button instead, uh, we gonna do in a
different way.
So let me show you.
So if I right click, as you can see, as soon as we clicked right, uh, on our keyboard, sorry.
Uh, right click mouse button, we can see this victory us gets pop up.
So we don't want that to happen instead of, uh, clicking right, uh, right mouse button where if
we at the end of the level, then we just want to win, uh, win our game.
And we just want to bring up this victory UI to do that, let's get out of play mode and we're gonna
open up our script.
So for that, uh, let's remove firstly.
So once we click right click our mouse button which is bringing bringing up our victory UI, which we
don't want.
So we're gonna remove that line of code and we're doing inside our player scape.
So let's head over to this hierarchy.
Let's select our player game object in the hierarchy.
And let's go to player skip in the inspector.
And let's double click on it in order to open that up.
So if I just move over to my update function in the bottom, I can see that if we clicking the right
mouse button, then we just triggering our victory UI.
Basically we just bringing up.
So we don't want to do this.
So that's why we're gonna remove this.
So let's remove that instead.
We're going to do a in a different way.
And now we're going to press down Ctrl S to save our script.
And now let's move over to unity.
So we want a flag at the end of the level.
And if our player GameObject trigger with that flag or collide with that flag, then we just want to
bring up our victory UI.
So just wait a moment and of course I will have the assets in the resources you can download.
Also, you can also you're gonna get some links.
Uh, you can check that out as well.
So just wait a moment and we need to drag our flag sprite.
So just wait a moment.
So now the compilation is done completely.
So let's head over to this project tab assets.
And I'm going to move over to my sprites folder.
As you can notice I have the sprite sheet of the flag right over here.
So I'm gonna select that.
Let's go over to Inspector.
Let's click on this open Sprite editor so we can see we have more than one.
So sprite mode we're going to leave it to multiple and pixel per unit.
We're going to choose something around 16.
And to get rid of blur we're going to choose point of filter filter mode to point filter.
And after doing all of these things click on this apply button in the bottom right.
As soon as we clicked on it, we can see the blurry is gone by now.
And now we need to slice individually.
So let's click on this slice in the top left in our Sprite Editor tab.
And we're going to select a type to uh automatic to create by cell count.
And let's count how many columns and rows we have so we can see one row and five columns.
So we're going to put five columns sorry uh five columns and one row.
Let's click on this slice.
And then let's click on this apply button.
And now it's done.
And I'm going to select my game view once again.
And let's go over to that sprite sheet.
And then click on this arrow in order to see the individual.
So I'm going to select the first one.
And let's drag it over to this in view.
And let's move it somewhere around here I guess this is pretty much fine.
And uh, let's call it uh, something like flak.
So I'm going to call this one a flag, and I'm going to select my flag, and I'm going to drag it in
the top of my hierarchy so I can see all the time.
And let's add some components to this flag.
Game object.
First thing I'm going to add a rigid body 2D.
And I will set it to kinematic.
So it's not going to fall down at all.
So let's click on this add component.
And let's add a rigid body 2D.
And let's set the body body type to kinematic and collision detection to continuous interpolate to interpolate
to making out smooth.
And we're gonna add one more thing which is which will be a box collider 2D for collision detection.
So let's click on this add component.
And we're gonna add a box Collider 2D.
And let's click on this Edit Collider to edit the collider as the size of our flag game object something
like this.
And we're going to check this is trigger to true.
Basically we just want to enable and we don't want our player register uh the register to pass through
this flag.
So that's why.
So our player easily can pass through this flag and it's gonna check with trigger.
So we just check this trigger.
So we're going to check with our trigger on trigger enter 2D function.
Basically once our player GameObject just gonna trigger with this flag or just gonna collide, then
we just want to bring up our victory UI.
But now let's leave it like this and let's make the animation by now, uh, to make the animation right
away, we do know that.
So let's go over to that sprite sheet.
So so select click on this arrow and select the first uh to the end one by holding down shift.
Basically select all of the sprite by holding down shift and then drag it over to the flag GameObject
in the hierarchy.
Top of this black flag GameObject in the hierarchy, so it's going to make the animation right away.
And now we have to choose a folder where we want to place the animation.
So we will go to top lib assets.
And then we will move over to our animation folder.
And we will move over to our other animation subfolder.
So we created those folder to just keep our project clean.
And now we have to name it.
Or you can create a separate folder as well separate subfolder by right clicking then new and then you
a new folder.
And you can name that folder to something like flag animation.
But I'm gonna just place my flag animation animation right over here.
So I'm going to leave that.
So let's call this animation clip to something like flag a flag, underscore animation like that.
And let's click on the save button.
And once we done and if we select our flag then move over to animation tab.
And then click on this play button.
As you can notice, it's playing the flag animation over a can and a can.
So basically this is fine by now.
And what we want to do, we want to tag this flag as a flag tag because we're going to check with a
trigger.
So we basically want to check if this player game object trigger with this flag game object flag game
object that we want our victory UI.
So we just want to specify this flag as a flag game object.
So this player game object know that this is our flag.
And we need to bring up our victory UI.
So that's why.
So we're going to select our flag GameObject in the hierarchy.
Then go over to Inspector Tag.
As you can notice it says tag.
So just click there and then click on this attack in the bottom.
Then click on this plus icon.
Name the tag whatever you want.
So I'm going to name it something like flag.
And then click on the save button and make sure you select your flag GameObject in the hierarchy one
more time.
Then go over to Inspector.
As you can notice, it says untagged.
So let's click on it and let's assign with the tag which we recently created.
And now as you can notice we assign it this flag as a flag.
Game object sorry flag tag.
As you can notice in the inspector.
And now let's turn this flag into a prefab.
So we're going to have the copy of it.
If we lost somehow missed missed mistakenly then we can just restore it directly.
So that's why we're going to make this one a prefab basically copy of it.
So we're going to select our flag in the hierarchy.
And let's drag it over to this prefabs folder in our project tab.
Now we turn it into a prefab.
And what we're going to do now we're going to open up our player skip.
But before I do I'm going to drag my player game object right over here for testing purposes only.
So I'm going to select my player GameObject in the hierarchy.
And let's press down F in order to focus on it.
And let's select the move tool in the scene view and let's move it at the end of the level, this player
game object, uh, let's move it, uh, somewhere over here.
And this seems pretty much cool.
So we can just test the game right away, or we can check it right away.
And now what we need to do, we need to use Ontriggerenter 2D function.
So let's select our player game object.
And let's open up our player script in Inspector by double clicking on it.
And what we're going to do now we're gonna move over to Ontriggerenter 2D function.
Uh, so we have it over here.
And if you haven't included, then type this Ontriggerenter 2D function.
And you can ignore this line of code right over here.
Or you can ignore this if condition.
So what we're going to do right over here.
So this function get called when we trigger with something.
And we can extract information.
What we trigger it with by going over to this collision parameter.
So what we want to check if we trigger with a game object has a tag called flag that we want to, we
just want to trigger our victory UI.
Basically we want to win our game.
So that's why we're going to check right over here.
So let's use this if condition.
Let's make first bracket and some curly brackets.
And what we want to check over here.
We basically want to check if the game object has a tag called flag.
So we will go to collision collision dot game object.
And we're going to access dot tag.
And we will check if the tag is equals equals to our flag.
And make sure you do inside quotation.
And also make sure you're spelling it correct.
So collision dot game object basically basically means the game object we trigger it with.
So if this player game object trigger with this flag then collision dot game object they are basically
means this flag game object and what we're doing, which is accessing the tag of it, as you can notice.
And we're checking if it's equals equals to flag.
As you can see.
So we definitely gonna trigger with this flag game object.
And this flag game object has a tag called flag.
And we can notice in inspector means we just triggering with this.
Then what we want to do.
We just want to win our game.
For now we're gonna print out a message if it's working or not.
So for that, we're gonna move over to our script.
And over here we just want to print out a message for now, for printing out message, we're going to
type this debug.log.
Uh debug.log.
And in, uh, in quotation we can say whatever we just want to say.
Let's say something like victory, a victory, and let's close that up with semicolon.
And we're going to press down Ctrl S to save our script.
And now let's move over to unity a unity editor.
And let's have a look on this.
So as soon as we're going to trigger with this flag game object, you will able to notice the message
just going to pop up in the console says victory since we just printing out that that message only.
So let's have a look on this.
So just wait a moment.
Once our compilation is done we can just go ahead and check that out.
So I'm going to select my console tab.
And let's click on this play button in the top in order to play our game.
And let's have a look on this.
So just wait a moment.
And now if we just trigger with this flag, as you can notice, as soon as we trigger it with this flag,
the message in our console tab just getting pop up says victory as you can notice.
So instead of printing out this message, we just want to trigger our victory way.
Basically, we just want to bring up our victory.
You as you seen earlier.
So we're going to get out of play mode.
And let's open up our script by double clicking on this message.
So we can just move over to that line of code directly.
Or we can simply select our player and we can double click on this player script in the inspector to
open that line of code.
Or we can simply just double click on this message in order to move over to that line of code.
So let's double click on this.
So what we need firstly we need a reference of that victory UI.
So if we move over to hierarchy then canvas and then go over to victory UI, we have the BG.
And if we press down F on it we can see we have it over here.
So basically we need a reference of this BG, not this victory UI game object.
Basically this BG right over here as you can notice.
So we need a reference, then we can just bring this up.
Uh, so we already have it.
We do know basically.
Uh, basically, uh, if I select my player game object in a hierarchy, then go over to Inspector,
scroll down to player skip.
We can notice we have the victory BG, bg, UI.
As you can see.
So basically we need to call the function.
So whenever we clicking the right mouse button we do know that we just uh calling that trigger victory
key.
Uh we just calling that function.
So we're going to call this function over here by now.
So we're going to double click on this message.
So uh, after printing out message I just want to call the function.
And that function just gonna do the rest thing as we have done it.
So if I scroll down we made that function I guess in the up right over here.
As you can notice, we just, uh, made the function right over here.
So we need to call this trigger victory function.
And this function just gonna do the last thing that we have done earlier.
So now I'm gonna move over to, uh, right over here.
So after printing out message.
So I'm going to leave this message.
After printing out message, I want to bring up that, uh, victory UI PG.
So basically I need to call that function, which is trigger victory y.
So let's call the function over here and then make first bracket.
And let's close that up with semicolon.
And we do know that this function is just going to do the raise thing.
And we're gonna press down Ctrl s to save our script.
And now let's move over to unity.
So as soon as we're gonna trigger with this, uh, flag game object, you will able to notice that BG
just gonna pop up right away.
So just wait a moment and you will notice as soon as we're gonna trigger with this victory, uh, sorry,
this flag game object.
So let's, uh, it's done by now.
So let's click on this play button in the top in order to play our game.
And let's have a look on this.
So just wait a moment.
So now if we trigger with this flag, as you can see, as soon as we trigger it a this basically a victory.
YPG just gets pop up and it just bring up from the bottom.
And but the problem is that if we click on this menu we just going over to basically that's fine I thought
it's not working at all.
So if I just click on this play button, we're playing our game and we can see if we click on this next
button, we're printing out a message in the console say load next level.
So whenever we win this game we don't want to move left and right.
As you can notice, we just moving left and right.
We need to stop doing Once we we win the game.
So what we're gonna do, we're gonna get out of play mode, and we will create a bool parameter to just
keep track of if we win the game or not.
So we will open up our simply player script, or you can create a separate script for it, something
like Game Manager.
You can name that script and you can just create that.
But I'm gonna do inside my player script.
So that's why I'm going to open up player script by double clicking on it.
And let's go to top of our class, uh, right over here.
Uh, let's make the function over here.
And this function doesn't need to be public.
So we're going to make it private instead.
And this will be bool which just gonna keep track or keep track of if, if we win the game or not.
And we're gonna say if is game, uh, a victory, let's say something like victory.
Uh, we can say something like, we own the game.
Something like, let's call it victory simply.
Let's call it victory.
Uh, sorry.
It should be victory is victory.
Or let's, uh, I don't know what it's to call.
Uh, so let's leave it to victory, and let's close that up with semicolon, and I'm gonna move over
to this start function.
So in this start of the game, what I'm going to do I'm going to set victory equal to false.
Victory equal to false.
Why.
Because as soon as we're going to start our game, we're not gonna win our game right away.
So that's why in the start of the game, as you can notice, I just set this victory equal to false.
And this parameter we just created up over here, which is a bool parameter just gonna keep track of
if we win the game or not.
But if we trigger with that flag game object, then what we're gonna do, we're gonna set this victory
to true.
Why?
Because we just own the game and we just trigger it with this flag.
Basically means we own the game.
So what we're gonna do, we're gonna move over to that line of code.
In which line of code we just triggering with that flag so we can see we are doing right over here.
So what we're going to do now, we're going to set our victory.
Sorry.
We will say our victory equal to true because we just trigger it with this flag basically means we just
add and add.
So I really apologize for this.
So we do know that if we if we add the end of the level and if we trigger with this flag basically means
we own the game.
So that's why I just said victory to true.
As you can notice.
So once we own our game, we don't want this player a game object to move left and right.
We just want to stop our player moving left and right and then jumping, doing all of those things.
So what we're gonna do, we're gonna move over to our script and we will go to update function.
Basically, we need to move over to that.
We we basically need to move over to that line of code in which line of code, which is moving right
over here.
As you can see, this movement parameter right over here is for is responsible for moving our player
left and right.
And we can notice we're just moving our player right over here.
As you can notice we flipping our player.
Are we checking.
Are we playing our animation.
We playing attack animation.
Basically all of these things we're doing inside our update function.
So before we do all of the all of these things, we just want to check if we already own the game,
then we don't want to do that like moving left and right or jumping.
So that's why we will go to top of our class.
And before we move or jam?
Jam our player.
We just want to check if we own the game or not.
So we're going to use this if condition.
Let's make first bracket and some curly brackets.
And what we want to check over here.
We basically want to check if we own the game or not.
So we will check.
And we do know that we just created this vector parameter in order to basically to just keep track of
if we win the game or not.
So if victory is equals, equals to true or basically means like if you just leave like this, it basically
means true means we own the game.
Now what we have to do, we need to stop moving left and right.
So inside this curly brackets, basically we need to type this return.
And let's close that up with semicolon.
And we do know that after return, whatever we're gonna do it's not gonna be executed at all.
Basically we will stop moving this player left and right, jumping, playing attack animation and all
of those things.
So before we doing all of this, all of these things, we checking if victory is equals equals to true
or if victory if that is the case, we type in return.
And we do know that after return, whatever we're gonna do, it's not gonna be executed at all.
Basically means our player not gonna move left and right, not gonna play jumping animation clip, not
able to attack once we own the game.
So basically that is the thing.
So I hope you get the idea that why we created this victory parameter in order to keep track of if we
own the game or not, and we just checking with that parameter to do something and I'm gonna move this
over here and this seems pretty much fine.
And if you want to move any line of code anywhere, you can just hold down alt on your keyboard and
you can use up and down arrow key on your keyboard to just move up and down.
And I'm gonna remove this comment from over here as well here.
And we created a player type parameter which is not useful.
So we're gonna remove that.
Let's remove that and we get a pop up.
So let's remove this as well.
Or let's leave that.
It's gonna be fine.
Uh that is bool.
Let's call it is player type as we have it done.
And you can basically ignore these things and it's up to you.
You can ignore that.
And we're gonna press down Ctrl s in order to save our skip.
And now let's move over to unity.
So now, by now, as soon as we're gonna trigger with this flag GameObject, that BG is gonna pop up,
which is victory, and we will unable to move left and right once we win the game.
So just wait a moment and once we done, we can just check that out.
So let's click on this play button in the top in order to play our game.
And let's take a look on this.
So as soon as we're gonna trigger with this flag game object, we will unable to move later.
Right.
Jumping and playing attack animation clip.
So let's have a look on this.
So I'm gonna flag as you can see.
But the problem is that we, we can notice our player is still moving.
So what we're gonna do, we can get out of play mode.
And we just want to set the movement parameter to zero as well as the speed.
So this player game object not gonna move at all.
So what we're gonna do, we're gonna open up our player script by double clicking on it.
And we will go to over here.
So we're doing so what we want to do, we just want to set the movement parameter to zero as well as
we can just set the speed to zero.
So this movement right over here as you can notice it's responsible for moving.
So once we win the game.
We just want to set this movement parameter to zero.
So this player right over here, it's not gonna move at all.
Basically that is the thing.
So before we type return we're gonna set movement equal to zero.
And let's close that up with semicolon.
And we're gonna press down Ctrl s to save our script.
And now let's move over to unity.
And it should be fine by now.
And if it's not working, then we also need to set our move speed to zero.
So, uh, it's not gonna move at all.
So let's have a look on this.
If it's not working, then we also need to set our move speed to zero, so it's not gonna move at all.
Let's click on this play button one more time in the top in order to play our game.
And let's have a look on this.
So just wait.
And if we trigger with this flag, as you can see, uh, which is, uh, stops moving to the left and
right.
And if I press down space key on my keyboard, as you can notice, we not jumping at all.
But if you take a closer look, basically, if I select my player in the hierarchy and press down F
in order to focus on it, we can notice it's playing the running animation clip over again and again,
which we don't want.
We want to play the idle animation clip instead of the running one.
So what we need to do, we need to get out of play mode.
And if we select our player in the hierarchy, then go over to animator tab.
As you can see this run parameter.
We do know that if we set this run parameter to one, it's going to play the running animation clip.
And we do know that if we set this run parameter to zero, it's going to play the idle animation clip.
So once we we win the game we just want to set this run parameter to zero.
So this player is not going to play the running animation clip over again and again, and if you little
bit confused, then you can check out previous lecture where we set up our animation of this player
so you can check that out.
So what we're gonna do and this run parameter right over here is a float parameter.
So basically we need to set that up.
So let's go to script.
So after setting movement to zero we also want to play the idle animation clip.
Basically we need to set that parameter to zero.
So firstly what we will do we will go to animator.
And we do know that we have it reference of this animator component.
And we can check that out over here.
Right over here.
And in the start of the game we just getting the animator component.
As you can notice.
Basically we have the reference of it.
So now we have the animator component.
And we're going to use dot set float function and make this brackets.
Why we using we we using this set float function.
Because this one parameter right over here is a float parameter.
So that's why we need to use this set float function.
And this set float function as a first argument.
It's going to take in quotation the parameter name and make sure you just spelling it correct.
So we can say run.
So in quotation we need to pass the parameter name which is one.
And the second thing comma you need to set the value.
So we do know that if we just set it to zero if we set it to zero, it's going to play the idle animation
clip.
Why?
Because if we move over to unity and select this player GameObject in the hierarchy, then move over
to animator tab.
And from this idle to from run from run to.
If we choose this uh to idle and select this transition and then go over to Inspector and scroll down.
We can see that if run is less than 0.01.
So we do know that if we set this run to zero and zero will be less than 0.1.
So the condition is getting true.
So that's why this idle animation just gonna play.
Because we have chosen that condition as you can notice.
So basically we need to set it to zero F.
And we're going to close that off with semicolon.
And we're going to press down Ctrl S to save our script.
And now let's move over to unity.
And by now it's gonna be fine.
So let's have a look on this.
So as soon as we're gonna trigger with this, uh, flag GameObject, firstly that, uh, just gonna
pop up and this player will stop moving left and right, and then it's gonna play the idle animation
clip instead of the running one.
So now if we just go ahead and then click on this play button, it should be it should work fine.
So just wait a moment and if you bit confused then you can check out, uh, previous lecture where we,
uh, set those animation transition and we created those animation clip.
So now if I just trigger with this flag, as you can see, as soon as we just trigger it, this factory
VG just gets pop up.
And by now we can notice in this in view, our player is now playing idle animation clip over again
and again.
And we can notice in the animator tab as well right over here as you can see.
So I hope you get the idea that how you can do it and we can get out of play mode and what we need to
do, we also need to place our some diamonds and hearts and all of those things.
So we need to do and we're going to do it in the next lecture basically.
Sorry not diamonds basically fruits and this heart.
So we basically need to make the level.
So I hope you get the idea that how you can do it.
And I'm gonna press Ctrl s to save my script.
Sorry not save my script.
Basically the project I want to save.
So make sure you just press down Ctrl s on your keyboard to save your project.