So what we're gonna do now, uh, we're gonna import in our project Lean Twin.
We're gonna import that.
So how we can do that?
For that, we will head over to google.com and make sure you go to Unity Asset Store.
And in the top bar, search Lean Twin.
And once you get it right over here I have it.
So right click on it and then click on this open link in new tab.
So it's gonna open up in a new tab.
You're gonna see a button something over here add to my assets.
So just click there.
And once you're gonna click on it you're gonna see this open in unity.
So just click there in the top bar.
Uh we get a pop up says Open Unity Editor.
So just click on this Open Unity editor and it's going to take you to this unity editor.
So for uh, for that you will be something over here package manager.
And then link to it.
Let me show you.
So you will be right over here Lane.
Twain.
Lane.
Twain.
So search there or it's going to take us directly to Lynn Twain.
So just wait a little moment.
And once we just, uh, download it, we're just going to import in our project.
So just wait a little moment.
Uh, it's it's going to depend upon how much internet your internet speed is.
So as you can see, you're going to see a download button, something over here or a install button.
Uh, so just click on it.
And once you were done then click on this end project.
Uh, basically you're going to see an import button.
Then click on it.
And in the bottom right you can see import.
So just click on it and it's gonna import link to it in your project.
So since I already done it so I'm gonna cut this tab by now.
And if we move over to our project tab assets we can see a new folder which says Lane Twin.
And we have all of the script inside this lean twin to just make cool animation, that's why.
So now what we're going to do, we're going to drag this BG or this BG basically in the bottom we don't
want in the start of the game.
So if I just go add and then click on this play button, you will able to notice it will be centered
in our game view.
So we don't want this this big BG BG by default in the start of the game.
We do want once our player game object loses all of his health.
So as you can see we able to notice this.
We can click on this retry button and this menu button.
And we don't want this to be to be active by default.
So when I get out of play mode.
And for that we will head over to hierarchy then canvas.
And then we're gonna select this game over UI.
Then underneath over here we have the BG.
So make sure you select the BG not the a game over game object itself.
So we're going to select our page and select the move tool in the scene view.
And let's move it down.
Something over here in the way we're gonna move it something -1002 hundred.
As you can notice in Inspector something over here.
And we want to get this once our player game object just dies or loses all of his help.
So we need to open up our player script where we are doing it.
So I'm going to select my player GameObject in the hierarchy.
Let's open up the player script where it's dying.
So we're going to double click on it in order to open that up in Visual Studio.
And it's going to take a few moments to open that up.
And once we open up, we can just scrape that.
So just wait a moment or we can simply create a separate script for that as well.
So just wait a moment.
And once it's done, we can just go ahead and check that out.
So make sure you import in your project lint twin.
Of course I will have in the resources on this or in the source code.
You can check that out.
So just wait a moment.
It's gonna take a few moments, uh, depending upon on your system.
If you do have a fast system, then in your case, it might take around few seconds.
But if you do have a slow system, then in your case, it can take up to two minutes, something like
that.
Uh, so my system is slow, so that's why it's taking a lot of time.
And we're going to move over to our player script where a player is dying.
So if we move over to player Skip and scroll down to the bottom.
We made a dive function.
And over here, as you can notice.
So we just made the dive function.
So what we need to do we need to destroy our player game object when it loses all of his health.
So we only printing out this message says this dot GameObject dot name plus type basically player type.
And after that we just want to destroy our player and to destroy it, we're going to use this destroy
function.
So let's use this destroy and destroy and this destroy function as a first argument.
It's going to take the game object that we want to destroy.
So we're going to pass this game object.
And this dot game object basically is just referencing itself.
Basically the player game object itself.
And if you do want to destroy your player game object after some period of time, then as a comma you
can put the time as a second argument.
Since I want to destroy my player game object right away.
So that's why I'm not gonna put any second condition.
And let's close that up with semicolon.
And we're gonna press down Ctrl s to save our escape.
And now let's move over to unity.
So as soon as we're gonna lose all of our health, we will able to notice our player GameObject just
gonna destroy itself right away.
So just wait a moment.
And we also need to create a script called Game Manager.
And it's just gonna keep track of if the player game object is die or not.
And we're gonna make a game over UI script, game over UI script to just, uh, to just get this in
the center once our player GameObject dies or loses all of his health.
So just wait a little moment and once it's done, we can check that out, but we're gonna get some error.
So let's see if we get some error or not.
And we can see player died, as you can notice.
And if we move over to console tab, we're not getting any error.
It basically means it's fine.
So we're going to get out of play mode.
And what we're gonna do now we're going to bring that up.
So once our player GameObject destroyed itself we want the game over UI screen right over here basically
that big.
So to get that, uh, we can we need to grab the reference of this BG.
So if I select, uh, if I move over to Hierarchy canvas and then game over and select this BG and press
down F in order to focus on that.
We want this BG to be centered.
So basically A in the Y we just want to put zero.
So it's going to be somewhere around here or in the center of the game.
So we want that.
So we need a reference of this BG.
Then we can do that.
So let's grab the reference.
So we will move over to our scape.
And let's go to top of our class.
And let's grab the reference first of it.
So we're going to do it.
Something over here.
So let's give it a title.
So we're going to type this header for our title.
And let's call this one something like UI.
And sorry u I and we need a reference of that game object.
So we're going to make a serialized field sorry serialized field private.
And that BG itself a game object.
So we're going to type game object and we can call this one something like BG or background or bg UI
or Game Over You by as well we can call it, but I'm gonna leave it as BG and we're gonna close that
up with semicolon, and we're going to press Ctrl S to save our script.
And now let's move over to unity.
So underneath our player Skip we will able to notice.
And first thing is uh first thing we will able to notice the title.
And underneath of it we will able to notice that uh basically BG so what we need to do there, we basically
need to drag this page into that slot.
So we will have this widget.
And after that we can just put it in center.
So now what we're going to do if we select our player GameObject in the hierarchy then move over to
Inspector, then player Skip.
In the bottom we can see UI title, and underneath of it we can see BG and it says non game object basically
empty.
So we're going to take our BG underneath our game over UI.
So make sure you select the BG not the game over UI.
So we're going to select that and let's drag it over to that field.
And now we can notice we have the BG basically this one.
Or simply you can call this one.
And now we ready to set this in the Y to zero.
To do that let's open up our player script by double clicking on it.
And what we're going to do.
We're going to move over to our die function where we're dying basically once our sorry, once we loses
all of our health and we want this to be centered in the why.
So I'm going to move over to our die function where we destroying our player.
So in the bottom over here as you can notice.
So before we destroy we just want to set the position.
So we're going to use this BG dot uh dot Lin move.
So we're going to use this Lin move local y.
So make sure you use this.
So firstly we're going over to that BG GameObject.
And we imported Lin tween.
So that's why we able to use this.
So make sure you just use this function.
It's called BG dot Lin.
Move local y and this function as a first argument.
It's going to take the position where we want to uh just want to go or so in the Y.
We want to go.
So that's why we're gonna use this Lin move.
We use this this Lin move local Y.
So in the Y we want to put it zero and zero is just going to be the center basically.
And the second thing, it's going to take the time after how much amount of time you just want to move
your PG in the Y axis to that point.
So after something like 0.8 second and less than one second, and after doing that, make sure you use
this dot.
So get out of the bracket and then use this dot set is so the since we want to use animation.
So that's why we're going to use this set is a set is our pack.
Or you can just use any of them.
It's basically up to you.
So I'm going to use this set is Expo this set.
Sorry out uh let's use this one.
Set is as is sorry set is our pack.
And then make this first bracket and then 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.
So as soon as our player GameObject just gonna die we just is moving this PG in the Y to zero position.
Basically, in the Y it's going to be zero means A, it's going to be center center of the game, and
it's going to pop up under, uh, basically after 0.8 second and we just use it dot set out back to
just make the animation.
So now let's click on this play button.
Not the animation.
Basically a cool thing.
You can assume it's going to pop up with a cool animation uh, or looping or something like that.
You can simply say, so now what we're going to do, we're going to take damage from this, uh, fire
and this saw.
And as you can see, indeed, as soon as our player GameObject dies, this BG just pop ups with cool
animation.
And let me show you one more time.
So I'm going to get out of play mode.
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 what we're going to do, we can see we are taking damages.
And as soon as we're going to lose all of our health, as you can see, indeed it just pop up and it
just pop up with nice animation.
Or you can say with nice transition animation, something like that, you can assume.
So we're going to get out of play mode.
And what we want to do, we want to set this in the start of the game of this PPG position in the start
of the game.
Something over here instead, instead of manually dragging in the bottom side.
As you can see, we already done it.
Instead of doing that, we're going to do it through our code.
So I'm going to move this, uh, BG something over here.
So in the start of the game I'm going to set the position of this BG, something like over here.
So in the Y why, we just want to have the position something like -1002 hundred.
As you saw earlier, as you've seen earlier.
So we're going to do that.
So let's go to script and we will go to start function.
So let's scroll up to the our player script.
And over here we have the start function.
So this start function get call in this start of the game.
So in the start of the game what we want we're going to set the position of that page.
So we will go to page dot transform dot local position dot local position.
And we're gonna set equal to a new Vector3 Vector3 which gonna have x axis y axis and the z axis sorry
z axis.
And then close that up with semicolon.
So what we basically doing we just going over to that PG.
Uh, basically this PG then going over to transform and then accessing the local position and this local
position just gonna going to have x axis, y axis and the z axis.
So that's why we just set equal to a new vector three which which gonna have x axis y axis and the z
axis.
So since we want in the y something in the bottom somewhere around here.
So over here the position is just going to be something like -1500 like that or -1200.
So I'm going to put something like in the Y -1000 1500 F.
And in the, in the Z axis we don't want to change at all anything like that.
So that's why in the Z we're going to put zero F in the x.
We're going to do the same thing zero f.
So we only changing in the y.
So now if I press down Ctrl s on my keyboard and then move over to unity, you will see as soon as we're
going to start our game this BG, BG position, it's just going to be in the Y axis, something around
-1500, as we have done inside that start function.
So just let let's take a look on that.
So just wait a moment.
And now this is fine.
So let's click on this play button in the top.
You will see as soon as our game.
Just gonna start.
This BG will be somewhere over here in the bottom.
But once we're gonna lose all of our health then this BG just gonna pop up with nice animation transition,
something like that.
So let's take damage.
As you can see, as soon as we started our game, this BG just set itself in the Y and we can just go
over to Inspector and we can just take a look of the position, as you can see, which is -1004 hundred,
I guess we have done uh, 1005.
Okay.
So basically that is fine.
It's totally up to you.
Uh, so I hope you get the idea.
And if I just take damage or all of the basically loses all of our health, we can notice it just pops
up right away once we loses all of our health.
As you can notice.
But the problem is that if we click on this retry button and then this menu button, it's doing nothing
currently.
So we need to hook this button with some certain function in order to do some specific things.
So I'm going to get out of play mode and I hope you get the idea.
And I also want this manually to in the bottom.
So it's gonna be clean.
So that's why.
So for that I'm going to head over to my hierarchy, then canvas and then Game Over UI, game object,
then PPG.
And let's move it down somewhere around here and make sure you select your parent game object.
Then go over to Inspector Overrides and then click on this Apply All.
So the changes you made it's going to be save.
And I'm going to press down Ctrl s on my keyboard in order to save my project.