WEBVTT

00:00.040 --> 00:02.960
We will create a game manager script and that script.

00:02.960 --> 00:07.280
Just going to keep track of this player game object is active or not.

00:07.320 --> 00:12.680
But before we do, let's open up the player script and we're going to destroy this player player game

00:12.720 --> 00:15.520
object once it loses all of his health.

00:15.600 --> 00:20.720
So let's select the player game object in the hierarchy, and let's open up the player script by double

00:20.720 --> 00:21.760
clicking on it.

00:22.080 --> 00:25.040
And let's go to bottom basically two die function.

00:25.040 --> 00:28.680
As you can see, we only just printing out the message in the console.

00:29.240 --> 00:30.240
Player died.

00:30.240 --> 00:33.640
And after that we also need to destroy our player game object.

00:33.640 --> 00:35.720
Basically it loses all of his health.

00:35.720 --> 00:36.560
So that's why.

00:36.720 --> 00:40.440
So we're going to use this destroy function in order to do that.

00:40.440 --> 00:45.760
So going to use this destroy destroy and this over here as a first argument.

00:45.760 --> 00:48.320
It's going to take the game object you want to destroy.

00:48.320 --> 00:50.520
So we're going to pass this game object.

00:50.520 --> 00:55.240
It's basically mean just it just referencing itself and comma.

00:55.280 --> 01:00.350
If you just want to specify the time after which amount of time you want to destroy.

01:00.390 --> 01:03.950
Then as a second argument, you can pass that.

01:03.950 --> 01:05.790
But I don't want any delay.

01:05.790 --> 01:08.070
I just want to destroy it right away.

01:08.070 --> 01:12.150
So that's why I'm gonna pass this date, this game object only.

01:12.150 --> 01:14.550
And after that, we're going to close that up with semicolon.

01:14.550 --> 01:17.310
And let's press down Ctrl S to save our script.

01:17.310 --> 01:19.230
And now let's move over to unity.

01:19.550 --> 01:25.470
So as soon as this player game object is going to lose all of his health, you will see this game object

01:25.470 --> 01:27.510
will destroy right away.

01:28.350 --> 01:29.910
So just wait for to compile.

01:33.110 --> 01:38.030
It's gonna take a few moments and once it's done, we are ready to do that.

01:38.350 --> 01:45.590
So now, uh, if we click on this play button in the top, you will see as soon as this player game

01:45.630 --> 01:50.350
object is just gonna lose all of his health, it will destroy itself right away.

01:50.710 --> 01:55.870
But if you want to delay, then you can just put as a second argument the time as well.

01:55.910 --> 01:58.590
But, uh, but let's have a look on this.

01:59.550 --> 02:05.350
Once this player game object loses, then as you can see, four, three, two, one.

02:05.550 --> 02:09.150
As you can see, another player just died right away.

02:09.150 --> 02:13.310
But the problem is that camera is still moving to the right direction.

02:13.310 --> 02:20.310
Once our player game object just dies, then we just want to stop this camera to move to the right direction.

02:20.310 --> 02:23.470
So that's why we're going to create a script in order to do it.

02:23.790 --> 02:28.670
Basically, we're gonna create a game manager script, and it's just going to keep track of if the game

02:28.670 --> 02:33.310
is active or not, or the player game object is still alive or not.

02:33.310 --> 02:36.430
So let's get out of play mode and let's create that.

02:36.430 --> 02:40.390
So I'm going to move over to project tab then assets and then scripts folder.

02:40.430 --> 02:45.830
Let's right click there then create and then Monobehaviour script and name that script to something

02:45.830 --> 02:47.270
like Game Manager.

02:47.270 --> 02:51.430
I already created a Game Manager strip over here, as you can see.

02:51.430 --> 02:57.700
So we can simply attach this script to any game object of our hierarchy, or we can simply create an

02:57.740 --> 02:59.580
another GameObject for this script.

02:59.580 --> 03:00.580
So let's do that.

03:00.580 --> 03:02.660
Let's right click or hit this plus icon.

03:02.660 --> 03:04.500
Let's create an empty game object.

03:04.500 --> 03:08.260
And I'm gonna name this GameObject to something like Game Manager.

03:08.580 --> 03:10.180
So let's call it Game Manager.

03:10.180 --> 03:11.580
And let's go to transform.

03:11.580 --> 03:13.620
Let's right click there reset.

03:13.620 --> 03:15.460
And I'm going to select my Gamemanager script.

03:15.460 --> 03:19.660
And I'm going to drag it top up in my hierarchy so I can see all the time.

03:19.660 --> 03:24.380
And let's select the Game Manager script and let's drag it over to this Add Component section.

03:24.700 --> 03:26.060
And in the Inspector.

03:26.060 --> 03:30.980
So now we're going to open up our player this Game Manager script by double clicking on it.

03:32.060 --> 03:35.900
And I'm going to remove this start and update function I don't need.

03:35.940 --> 03:37.940
Instead we're going to make a parameter.

03:37.940 --> 03:43.940
And we're going to make that parameter to public because we're going to access this parameter through

03:43.940 --> 03:49.660
another class or another, uh, basically another uh script you can say.

03:49.940 --> 03:53.340
And that will be bool, which can be true or false.

03:53.420 --> 03:56.090
Uh, basically this bool parameter over here.

03:56.090 --> 04:01.650
It's just going to keep track of if the game is active or the player game object is alive or not.

04:01.650 --> 04:06.770
And I'm gonna call this one is game active is game Active.

04:06.970 --> 04:09.410
And let's close that up with semicolon.

04:09.410 --> 04:11.690
And I'm going to use this start function.

04:11.690 --> 04:13.730
So let's include the start function.

04:13.730 --> 04:16.730
So this start function get called in the start of the game.

04:16.730 --> 04:18.850
So in the start of the game I'm going to set.

04:18.850 --> 04:21.450
This is a is game active parameter to true.

04:21.490 --> 04:27.250
Basically once our game start is is game active parameter should be true.

04:27.250 --> 04:33.090
But once our player game object destroy then we're gonna set the is game active parameter to false.

04:33.090 --> 04:35.170
So I'm going to use this is game active.

04:35.170 --> 04:38.490
And we're going to set equal to false in the start of the game.

04:38.490 --> 04:44.570
And we're going to create a singleton pattern to just access this game manager script through another

04:44.570 --> 04:49.010
class or this parameter in another class simply.

04:49.250 --> 04:54.690
Uh, so if you haven't watched the singleton lecture then you can go and check that out.

04:54.690 --> 05:00.770
Or you can simply use find any object by type, and you can simply pass the script name and you can

05:00.770 --> 05:02.090
access the parameter.

05:02.090 --> 05:08.970
But instead of doing fairly taxing it, basically it's fairly taxing and it's heavy text texting.

05:08.970 --> 05:11.810
So that's why we're going to use this singleton pattern.

05:11.810 --> 05:15.130
So we're gonna use this public static static.

05:15.130 --> 05:21.410
And we're going to create a parameter as the same name as same name of our script or class.

05:21.570 --> 05:24.730
And I'm going to call this one instance instance.

05:25.090 --> 05:26.930
Let's close that up with semicolon.

05:26.930 --> 05:29.290
And let's move over to start function.

05:29.290 --> 05:35.850
And over here I'm going to do I'm going to check if instance equal to equals equals to null.

05:35.850 --> 05:39.810
Basically means there is no instance of this a game manager.

05:39.810 --> 05:42.410
Then I'm going to set instance equal to this.

05:42.410 --> 05:49.490
And if there is already an instance then I'm going to destroy this, uh, player script or this instance.

05:49.490 --> 05:52.800
So I'm going to say uh, we're going to use this destroy function.

05:53.040 --> 05:58.360
And I'm going to say this, dot this, and let's close that up with semicolon.

05:58.680 --> 06:04.000
Uh, if you a little bit confusing, then you can simply use find any object of type.

06:04.000 --> 06:05.880
Then make arrow brackets.

06:05.880 --> 06:12.240
And then in that arrow brackets you can pass the script name as we have done in the start of the game.

06:12.280 --> 06:17.440
Basically, once we started coding we just use that, find any object by type.

06:17.600 --> 06:23.360
And if you want to learn about more, uh, singleton pattern, then you can check out the Singleton

06:23.360 --> 06:25.480
pattern lecture in my course.

06:25.720 --> 06:28.920
And now I'm going to press Ctrl S to save our script.

06:28.960 --> 06:30.600
And let's move over to unity.

06:31.200 --> 06:33.200
So we're going to press down Ctrl S.

06:34.760 --> 06:37.520
And we're going to open up our player script.

06:37.840 --> 06:40.160
Uh basically where the player is dying.

06:40.280 --> 06:43.400
So let's select the player game object in the hierarchy.

06:43.400 --> 06:46.400
And let's open up the player script by double clicking on it.

06:46.400 --> 06:49.880
So as you can see, player game object is dying over here.

06:49.880 --> 06:53.240
Or we simply destroying our player game object right away.

06:53.360 --> 06:59.480
So before we destroy, I'm going to set this game active parameter in our Gamemanager script to false

06:59.480 --> 07:02.800
because our player game object totally get destroyed.

07:02.840 --> 07:03.600
So that's why.

07:03.640 --> 07:08.640
So before we die, before it's died, we're going to set this parameter to false.

07:08.640 --> 07:10.360
So we can simply use this.

07:10.360 --> 07:12.080
Find any object by type.

07:12.120 --> 07:17.320
And in this arrows you have to pass the name of the script or the script that you're looking for.

07:17.400 --> 07:22.120
So in our case Gamemanager then make first packet and then use this dot.

07:22.120 --> 07:23.680
And we're going to say is game active.

07:23.680 --> 07:25.600
We're going to access that parameter.

07:25.600 --> 07:28.600
And we're going to set it equal to false before we die.

07:28.640 --> 07:33.640
But instead of using this we're going to use the singleton pattern as we created.

07:33.640 --> 07:37.160
So we can simply pass the script name which is our gamemanager.

07:37.160 --> 07:39.120
Then we will move over to instant.

07:39.120 --> 07:42.000
And then we're going to access the is game active parameter.

07:42.000 --> 07:44.360
And we will set equal to false.

07:44.600 --> 07:46.600
So let's close that up with semicolon.

07:47.160 --> 07:50.110
So we're just setting equal to false as you can see.

07:50.110 --> 07:54.990
So basically what we're doing, we're just moving over to this Gamemanager script and then accessing

07:54.990 --> 07:59.030
this scheme active parameter or this bool parameter as you can see.

07:59.070 --> 08:03.670
And by accessing and resetting this scheme active parameter to false.

08:03.710 --> 08:07.310
As you can see uh we just setting it equal to false.

08:07.310 --> 08:09.630
But one when we're just doing that.

08:09.670 --> 08:15.550
Once our player game object loses all of its health, as you can see, we're doing inside the die function

08:15.550 --> 08:17.150
and we're calling the die function.

08:17.150 --> 08:22.150
Once our player game object loses all of his health before it loses all of his health.

08:22.190 --> 08:27.270
Firstly, we just printing out a message in the console, says player died, and after that we're just

08:27.270 --> 08:28.990
going over to game Manager script.

08:28.990 --> 08:31.990
And then accessing that is game active parameter.

08:31.990 --> 08:34.150
And then we're just setting equal to false.

08:34.150 --> 08:37.950
And after that we're just destroying our player game object right away.

08:37.990 --> 08:43.470
As you can see now I'm gonna press down Ctrl s to save my script and let's move to unity.

08:43.590 --> 08:49.780
So as soon as our player game objects die, you will see that his is game active parameter just going

08:49.780 --> 08:51.420
to be false right away.

08:51.420 --> 08:58.260
And we can see underneath our game manager script as well, uh, in our Gamemanager game object.

08:58.260 --> 09:03.740
So if I select my Game manager uh, GameObject in the hierarchy, we can see underneath our Game Manager

09:03.740 --> 09:06.460
script we have an active parameter.

09:06.460 --> 09:09.740
And by default it's basically unchecked basically means false.

09:09.740 --> 09:14.260
But as soon as we're going to start our game, you will see this in-game active parameter.

09:14.260 --> 09:19.860
Just gonna be, uh, true right away, because in the start of the game we are setting this is game

09:19.860 --> 09:21.220
active parameter to true.

09:21.220 --> 09:22.860
So that's why it's going to be checked.

09:22.860 --> 09:28.100
So as you can see as soon as the game start is game active parameter is now true.

09:28.100 --> 09:33.380
But once our player game object loses all of his health, you will see this game active parameter just

09:33.380 --> 09:34.140
gonna be false.

09:34.180 --> 09:40.380
As you can see, as soon as our player game object dies, this is game active parameter gets false because

09:40.380 --> 09:45.180
once our player game object dies, we just setting this parameter to false.

09:45.180 --> 09:47.180
So let's get out of play mode.

09:47.180 --> 09:52.300
So we're going to use this is game parameter in order to move our main camera.

09:52.300 --> 09:54.940
So if it's game active parameter is false.

09:54.940 --> 10:00.980
Basically means our player game object dies means we need to stop moving this main camera.

10:00.980 --> 10:05.660
So let's open up the follow script where we simply moving our camera.

10:05.660 --> 10:09.020
So I'm going to select my flow follow script in the script folder.

10:09.020 --> 10:16.180
Or we can simply select the camera parent in which game object we just created the follow script.

10:16.180 --> 10:19.300
So and you you can see in our camera parent.

10:19.300 --> 10:22.260
So I'm going to open that up by double clicking on it.

10:22.260 --> 10:24.700
So we're moving the camera over here.

10:24.700 --> 10:28.300
So before we move we're going to check if the game is active or not.

10:28.340 --> 10:30.900
Means our player game object is alive or not.

10:30.940 --> 10:34.380
If it's not then we need to stop moving our camera.

10:34.380 --> 10:35.980
So we're going to check before we move.

10:35.980 --> 10:36.780
We're going to check.

10:36.820 --> 10:39.540
If so we will go to Game Manager script.

10:39.540 --> 10:41.460
Then we're going to go to instant.

10:41.460 --> 10:44.300
And then we're going to access the is game active parameter.

10:44.300 --> 10:47.370
And we will check if this equals equals to false.

10:47.370 --> 10:51.170
If that is the case means our player game object totally get destroyed.

10:51.170 --> 10:52.970
So we're going to make some curly brackets.

10:52.970 --> 10:58.810
So in that situation what we need to do we need to stop moving our main camera or the camera parent

10:58.850 --> 11:00.450
to the right direction.

11:00.450 --> 11:02.050
So we're checking over here.

11:02.050 --> 11:07.890
So we're just going to game manager then instant and then accessing the parameter which is game active.

11:07.890 --> 11:10.570
And then we're checking if it's equals equals to false.

11:10.570 --> 11:16.010
Basically we're just going over to this Gamemanager script and we accessing this game active parameter.

11:16.010 --> 11:19.570
And we're just checking if this equals equals to false.

11:19.570 --> 11:21.530
And we do know where we're setting.

11:21.530 --> 11:23.730
This is game active parameter to false.

11:23.890 --> 11:30.010
When our player game object as as you can see at that moment we're just setting it equal to false means.

11:30.010 --> 11:32.170
Our player game object is totally.

11:32.170 --> 11:36.930
So in that situation what we need to do, we need to stop moving our main camera.

11:36.930 --> 11:39.130
So the main camera or camera plane.

11:39.170 --> 11:41.090
So that's why we're going to type this return.

11:41.090 --> 11:45.560
And we do know after return whatever we're gonna do it's not going to be executed.

11:45.560 --> 11:49.080
Means our main camera will stop moving to the right direction.

11:49.440 --> 11:50.880
So firstly we're just going.

11:50.920 --> 11:54.440
Are we basically checking is game active parameter is false or not.

11:54.480 --> 11:56.120
If it's then we're just typing.

11:56.120 --> 12:00.520
Return means after return whatever we're going to do it's not going to be executed.

12:00.520 --> 12:07.520
So this line of code we are not going to execute means our camera parent or the main camera will stop

12:07.560 --> 12:09.360
moving to the right direction.

12:09.680 --> 12:11.200
So basically that is the thing.

12:11.240 --> 12:14.320
And now we're going to save our script by hitting Ctrl s.

12:14.480 --> 12:18.400
But before I do I'm going to make this one as cool.

12:19.760 --> 12:22.640
And I'm going to put this curly brackets over here.

12:22.640 --> 12:25.360
And I'm going to press Ctrl s to save my script.

12:25.360 --> 12:26.760
And let's move to unity.

12:26.760 --> 12:31.720
So you can use that Game Manager script to check everywhere whatever you're doing.

12:31.760 --> 12:36.120
Like moving your crown, moving your main camera, like all of those things.

12:36.120 --> 12:37.640
So just wait for it to compile.

12:38.840 --> 12:44.800
And now it's fine if I select Game Manager and let's click on this play button in the top and have a

12:44.800 --> 12:45.800
look on this.

12:45.920 --> 12:51.320
So as soon as the player game object is gonna die, you will see this camera just gonna stop moving

12:51.360 --> 12:54.760
to the right direction or this camera parent game object.

12:54.760 --> 12:56.600
So let's have a look on this.

12:56.760 --> 13:00.560
As soon as this player game object is gonna die, you will see that.

13:00.840 --> 13:03.040
So it's taking damages.

13:03.680 --> 13:10.160
And we can see now, as soon as our player game object dies, we can see the camera just gets stops

13:10.160 --> 13:12.200
moving to the right direction.

13:12.480 --> 13:18.800
And before it dies, I also want to show the explosion effect, as we have done with this enemy two

13:18.840 --> 13:20.880
as well as enemy one game object.

13:20.880 --> 13:26.000
So we're gonna spawn our explosion prefab or the effect before we die.

13:26.040 --> 13:30.560
So let's get out of play mode and let's open up the player skip where we just want to show.

13:30.560 --> 13:32.680
So once our player game object dies.

13:32.720 --> 13:35.400
So I'm going to select my player game object in the hierarchy.

13:35.440 --> 13:38.440
And let's open up the player skip by double clicking on it.

13:38.440 --> 13:41.590
So we want to show up the explosion before we die.

13:41.630 --> 13:46.270
So before we die, we're going to use this instantiate function in order to spawn.

13:46.270 --> 13:52.270
So as a first argument it's going to take the game object or the explosion effect that you want to spawn.

13:52.270 --> 13:54.510
And the second thing it's going to take the position.

13:54.510 --> 13:56.990
And the third thing it's going to take the rotation.

13:56.990 --> 14:02.390
So let's make this one a comment by now for double forward slash.

14:02.390 --> 14:04.390
And let's go to top of our class.

14:04.550 --> 14:07.870
And we're going to make over here something over here.

14:07.910 --> 14:09.110
Let's do that.

14:09.110 --> 14:12.350
So we're going to make a serialized field that will be private.

14:12.350 --> 14:13.230
We're going to set.

14:13.230 --> 14:19.150
So even we set it to private we're still going to able to see this parameter underneath our player skip.

14:19.150 --> 14:19.390
Why.

14:19.430 --> 14:22.750
Because we marked as a serialized field as you can see.

14:22.750 --> 14:29.750
So if you little bit confused then you can just go over to my Clean Code chapter and then uh, and then

14:29.750 --> 14:31.750
serialized field, uh, lecture.

14:31.750 --> 14:38.550
So you can go and check that out how you can make your clean go, uh, how you can make your code clean

14:38.550 --> 14:44.860
so you can check that out about serialized field as well as Hide in Inspector and many things.

14:45.060 --> 14:50.660
So this will be game object that in explosion effect itself a whole game object.

14:50.660 --> 14:53.220
So that's why we need to type as a game object.

14:53.220 --> 14:59.780
And I'm going to call this one to something like explosion effect prefab or so.

14:59.900 --> 15:02.740
Simply we can type explosion effect as well.

15:02.740 --> 15:05.660
And now we're going to press down Ctrl S to save our script.

15:05.660 --> 15:07.060
And let's move to unity.

15:07.060 --> 15:12.580
So underneath our player Skip we're going to able to see in the bottom uh right before this maxhealth

15:12.580 --> 15:17.700
parameter a field will appear and we just name it Explosion Effect prefab.

15:17.700 --> 15:19.260
So what we have to right there.

15:19.300 --> 15:20.660
What we have to do right there.

15:20.660 --> 15:25.860
We basically need to drag the explosion effect GameObject into that slot.

15:25.860 --> 15:29.780
So I'm going to move over to my project tab, then assets and then prefabs.

15:29.820 --> 15:33.380
And I can see I have the explosion effect over here.

15:33.380 --> 15:35.420
So we can what we can simply do.

15:35.420 --> 15:39.620
But before we do I'm going to check uh, this folders as well.

15:39.620 --> 15:40.500
So I don't have.

15:40.500 --> 15:46.700
So I'm going to select my Explosion effect prefab game object and let's drag it over to that slot explosion

15:46.700 --> 15:49.580
effect prefab slot underneath our player skip.

15:49.580 --> 15:54.940
And now we can see we have the explosion effect game object and we are ready to spawn that.

15:54.940 --> 15:59.140
So let's go to Skip and let's move over to die function where we're doing.

15:59.180 --> 16:02.260
And I'm going to remove this slashes as the first thing.

16:02.260 --> 16:06.380
It's going to take the game object you want to show or the explosion effect.

16:06.380 --> 16:08.980
So I'm going to pass this explosion effect prefab.

16:08.980 --> 16:10.740
And we do know we just assign it.

16:10.740 --> 16:15.140
So make sure you just go to unity and drag the reference into that slot.

16:15.140 --> 16:17.100
And the second thing it's going to take the position.

16:17.100 --> 16:22.660
So I'm going to pass transform dot position means the center position or the current position of our

16:22.660 --> 16:23.940
player game object.

16:23.940 --> 16:26.100
And the third thing it's going to take the rotation.

16:26.100 --> 16:27.620
So I'm going to pass quaternion.

16:27.660 --> 16:30.300
Dot identity basically means no rotation.

16:30.300 --> 16:32.180
And let's close that up with semicolon.

16:32.180 --> 16:35.100
And we're going to press down Ctrl S to save our script.

16:35.100 --> 16:36.380
And let's move to unity.

16:36.700 --> 16:37.730
So we will see.

16:38.050 --> 16:41.170
Uh, as soon as this player came up, it's just gonna die.

16:41.250 --> 16:46.010
The explosion effect will be spawned at our player position.

16:46.170 --> 16:47.810
So let's have a look on that.

16:49.170 --> 16:54.530
So I'm gonna press down, uh, click on this play button at the top to play our game.

16:54.530 --> 16:56.650
And let's have a look on this.

16:57.690 --> 17:03.850
So as soon as this player game object just gonna destroy, we will able to see that explosion effect

17:03.970 --> 17:05.570
prefab right away.

17:05.570 --> 17:07.130
So just wait for to compile.

17:10.570 --> 17:19.410
So now we should able to see, as you can see, as soon as it's died we can see the explosion effect.

17:19.410 --> 17:25.490
But the problem is that, uh, if we move over to hierarchy, we can see still see the explosion clone

17:25.490 --> 17:31.530
or the explosion effect still laying around the hierarchy as well as in the scene view, as you can

17:31.530 --> 17:31.930
see.

17:31.930 --> 17:38.680
So after some period of time, we also need to destroy this explosion effect prefab as well.

17:38.680 --> 17:42.960
And we also need to adjust the explosion effect where we want to spawn.

17:42.960 --> 17:45.520
So we're going to create an empty game object for that.

17:45.520 --> 17:49.480
So let's get out of play mode and let's uh select the player game object.

17:49.480 --> 17:52.720
Let's right click on it and let's create an empty game object.

17:52.720 --> 17:55.560
And I'm going to press down F in order to focus on that.

17:55.600 --> 17:58.080
And let's select the move tool in this in view.

17:58.080 --> 18:00.600
And I'm going to move it somewhere over here.

18:00.880 --> 18:06.640
Uh so this basically I want to spawn from this, uh, position of that explosion effect.

18:06.640 --> 18:09.960
So that's why I just created an empty game object.

18:09.960 --> 18:17.400
And I'm going to call this a game object to something like explosion, uh, effect point or spawn point,

18:17.440 --> 18:22.080
explosion spawn, uh, position, or let's call it point instead.

18:22.240 --> 18:25.040
And I'm going to choose an icon for that.

18:25.040 --> 18:27.040
And this seems pretty much fine.

18:27.960 --> 18:35.840
So I'm gonna spawn it from here because, uh, as we seen this, the explosion just if spawning a more

18:35.840 --> 18:39.840
deeply or in the foot of our, uh, player game object.

18:39.840 --> 18:45.800
So I'm just gonna move it a little bit up, or I just want to show up a little bit from this player.

18:45.800 --> 18:46.200
Feet.

18:46.200 --> 18:47.840
So that's it's the reason.

18:48.040 --> 18:49.760
And let's open up the player script.

18:49.760 --> 18:55.560
But before we do, let's double click on this explosion, uh, effect prefab game object in our prefab

18:55.600 --> 18:56.160
folder.

18:56.320 --> 18:59.120
And after doing that let's go to animation tab.

18:59.120 --> 19:03.320
And we need to check the animation so we can see after 0.9 second.

19:03.440 --> 19:06.480
So this over here is basically means one second.

19:06.480 --> 19:12.680
So after 0.9 second it's just completing the whole animation clip as you can see.

19:12.680 --> 19:18.760
So after this period of time we need to uh, basically we need to destroy that, uh, this explosion

19:18.760 --> 19:20.800
effect game object as well.

19:20.800 --> 19:26.560
We need to destroy after this amount of time because it's just completing the whole explosion effect

19:26.600 --> 19:29.040
animation after this period of time.

19:29.040 --> 19:29.840
So that's why.

19:29.880 --> 19:32.160
So let's go back and let's go to script.

19:32.160 --> 19:36.070
So the first thing we need our position from where we want to spawn.

19:36.110 --> 19:43.350
Instead of spawning center position of player, we're gonna spawn that from that position as we created

19:43.350 --> 19:47.510
in in our hierarchy inside our player game object.

19:47.510 --> 19:53.590
So let's go to the top of our class and let's grab the reference, uh, basically the position from

19:53.590 --> 19:54.870
where we want to spawn.

19:54.870 --> 20:00.030
So let's create a serialized field that will be private and that will be transformed.

20:00.030 --> 20:01.350
Basically means position.

20:01.350 --> 20:10.470
And we can simply call it something like as explosion, explosion effect, spawn position or spawn point.

20:10.510 --> 20:11.350
Let's call it.

20:11.670 --> 20:17.750
And that's it I'm gonna call it explosion spawn point, something like that.

20:17.750 --> 20:20.430
And let's go to that script where we spawning.

20:20.430 --> 20:21.390
So over here.

20:21.390 --> 20:27.070
So I'm going to instead of passing transform.position basically means center position or the current

20:27.070 --> 20:30.390
position of our player game of a game object.

20:30.430 --> 20:34.910
I'm going to pass explosion if spawn point dot position.

20:34.910 --> 20:39.230
So we're going to spawn the explosion effect from this position.

20:39.230 --> 20:42.390
And we have the uh, we need to grab the reference first.

20:42.590 --> 20:47.950
And after spawning what we're going to do, we're going to store this explosion explosion effect that

20:47.950 --> 20:53.390
we spawn it, we're going to store it into another game object or a, another container, you can say,

20:53.430 --> 20:57.550
and we're going to call it temp effect, something like that.

20:57.550 --> 21:00.630
So we just created a game object called temp effect.

21:00.710 --> 21:06.710
Basically we just created a game object container because this explosion effect prefab itself a whole

21:06.750 --> 21:07.590
game object.

21:07.590 --> 21:11.710
So that's why we need to put it a container or in a container.

21:11.710 --> 21:16.710
Or you can simply say in a same variable or the same parameter name.

21:16.710 --> 21:22.030
So we created this temp effect and that is a game object type container.

21:22.030 --> 21:25.790
So firstly we spawn it at this position with no rotation.

21:25.790 --> 21:29.910
And after that we're just taking that we spawn it which is explosion effect.

21:29.980 --> 21:34.220
And then we're just storing into this stem effect after spawning that.

21:34.220 --> 21:40.900
So we also need to destroy this container or where we store it or where uh in which uh parameter or

21:40.940 --> 21:42.500
variable we store it.

21:42.540 --> 21:46.820
We also need to destroy that as well after some period of time.

21:46.820 --> 21:48.780
So we're going to use the destroy function.

21:48.780 --> 21:50.860
So let's use this destroy function.

21:50.860 --> 21:55.380
So it's going to take as a first argument that game object you want to destroy.

21:55.420 --> 22:00.820
So in our case stem effect or where we store that explosion effect after spawning.

22:00.820 --> 22:03.500
So in our case this stem effect we store it.

22:03.500 --> 22:05.700
So we also destroying this stem effect.

22:05.700 --> 22:08.140
And the second thing we're going to specify the time.

22:08.140 --> 22:14.260
So we do know that 0.9 second it's just completing the whole animation clip of explosion effect.

22:14.260 --> 22:17.660
So that's why as a second argument we're going to pass 0.9 F.

22:17.820 --> 22:19.860
And let's close that up with semicolon.

22:19.860 --> 22:22.500
And we're going to press down Ctrl S to save our script.

22:22.500 --> 22:24.780
And let's move over to unity by now.

22:24.780 --> 22:32.290
So you will see that explosion effect prefab will also be destroyed after 0.9 second after completing

22:32.290 --> 22:34.570
the whole animation clip of that.

22:35.930 --> 22:40.930
So just wait for it to compile and once it's done, we can simply select Player Game Object and let's

22:40.930 --> 22:47.890
go to overrides and then click on Apply All and we can see in our player skip a explosion effect prefab

22:47.890 --> 22:54.010
we have but the explosion spawn point we need to drag it and it says none transform basically empty.

22:54.010 --> 22:59.010
So we're going to select our underneath underneath our player game object which is explosion spawn point.

22:59.010 --> 23:01.130
And we're going to drag it into that slot.

23:01.170 --> 23:07.530
Now we have the explosion spawn point basically the position from where we want to spawn it.

23:07.530 --> 23:11.330
And now we're going to click on this play button in the top to play our game.

23:11.330 --> 23:13.330
And let's take a look on this.

23:19.850 --> 23:21.010
So just wait.

23:23.970 --> 23:34.530
And we will see that sorry we jump it a lot and we can see as soon as we die we can see the explosion

23:34.530 --> 23:34.890
effect.

23:35.890 --> 23:41.770
And if we move to hierarchy, we are not able to see that explosion effect prefab as well as in the

23:41.770 --> 23:48.410
scene view means after that amount of time, it just gets destroyed right away because we spawn it first

23:48.410 --> 23:54.410
and then we just taking that and we store it into this effect and we also destroying the temp effect

23:54.450 --> 23:59.450
after this amount of time where we store it, as you can see in our code.

23:59.450 --> 24:01.090
So I hope you get the idea.

24:01.090 --> 24:07.570
And we seen that the explosion effect is just spawning from feet of our player game object.

24:08.010 --> 24:10.730
So you can just adjust the position as well.

24:10.730 --> 24:17.370
If you just want to spawn it in a specific position, then you can create an GameObject and then you

24:17.370 --> 24:20.330
can just simply, uh, use that position.

24:20.330 --> 24:22.050
So I'm going to get out of play mode.

24:22.050 --> 24:26.770
So basically that is the thing I hope you get the idea of this how you can spawn it.
