WEBVTT

00:00.020 --> 00:00.560
Hello guys.

00:00.560 --> 00:01.520
Welcome to the video.

00:01.520 --> 00:05.360
In this one I want to show you how to make checkpoints okay.

00:05.360 --> 00:09.980
So let's go to the graphics item checkpoint.

00:09.980 --> 00:11.180
Checkpoint.

00:11.390 --> 00:13.220
Let's take this, uh.

00:14.290 --> 00:18.610
Actually, we need to take all of them and do pixel per unit 16.

00:18.910 --> 00:19.510
Okay.

00:20.790 --> 00:24.870
Now we have animation of checkpoint being activated.

00:25.290 --> 00:29.730
Then we have animation for checkpoint, like, you know, being active.

00:31.640 --> 00:34.130
And we have animation of an idle checkpoint.

00:34.430 --> 00:36.920
I'm going to take the sprite of an idle checkpoint.

00:37.920 --> 00:40.980
Let's switch sorting layer to items.

00:43.840 --> 00:44.980
Just like that.

00:45.280 --> 00:46.210
Uh, yeah.

00:46.210 --> 00:48.100
Let's do minus one over here.

00:49.500 --> 00:52.740
And let's name it as checkpoint.

00:53.560 --> 00:54.430
And just checkpoint.

00:54.430 --> 00:54.850
Yeah.

00:55.180 --> 01:00.640
Now I think we can place animator controller on the same game object, so it is easier to control with

01:00.640 --> 01:01.450
the script.

01:02.280 --> 01:07.230
And let's just go to scripts and make new C sharp script.

01:07.500 --> 01:08.730
Checkpoint.

01:10.990 --> 01:14.680
Now I'm going to open it and I'm going to do close all by this.

01:17.400 --> 01:26.430
Now over here, what we need is private animator animation, and I think we need a boolean that would

01:26.430 --> 01:29.940
say if checkpoint can be activated again.

01:29.940 --> 01:32.730
So we actually need to make a decision here.

01:33.060 --> 01:35.250
Uh, let's say you have a level like.

01:36.650 --> 01:37.250
This.

01:37.250 --> 01:40.670
And you have checkpoint here and checkpoint here.

01:40.670 --> 01:44.420
When player goes to the first checkpoint, it is activated.

01:45.800 --> 01:49.460
Then player goes to the second checkpoint and it is activated.

01:49.670 --> 01:57.500
Then let's say player jumps and dies somewhere here and where we're going to respawn the player on the

01:57.500 --> 02:00.140
last checkpoint or on the closest one.

02:00.140 --> 02:03.140
It is purely up to your decision, I think.

02:03.140 --> 02:08.000
Uh, to keep it simple, I will just respawn him at the last checkpoint activated.

02:08.000 --> 02:12.980
So we're going to need private bool can be activated.

02:14.610 --> 02:15.630
And also we need.

02:15.660 --> 02:16.020
Private.

02:16.020 --> 02:16.530
Bool.

02:16.530 --> 02:17.400
Active.

02:18.440 --> 02:21.800
Then we're going to make Ontriggerenter 2D.

02:22.190 --> 02:25.130
And over here we're going to get player player.

02:26.730 --> 02:29.670
Collision getcomponent of a player.

02:29.970 --> 02:31.650
And then we're going to need a method.

02:33.030 --> 02:38.700
Activate checkpoint, which will do one simple thing.

02:38.700 --> 02:42.030
It would say, uh enum.

02:42.030 --> 02:43.440
Set bool.

02:45.950 --> 02:49.010
Active to the Boolean of active.

02:49.770 --> 02:53.070
Actually, we could use trigger as well, I think.

02:53.070 --> 02:56.790
And actually we don't need this second boolean.

02:56.940 --> 02:58.200
I have a better idea.

02:59.760 --> 03:00.060
Yeah.

03:00.060 --> 03:01.830
So this is what it's going to do.

03:01.920 --> 03:08.430
Then over here we're going to do if player not equals to null then activate.

03:10.690 --> 03:11.590
Checkpoint.

03:12.040 --> 03:15.880
And over here at the start we're going to do.

03:18.430 --> 03:24.640
If active, then return so we cannot activate checkpoint again if it is already active.

03:24.640 --> 03:27.340
And also of course I forgot to do it here.

03:27.340 --> 03:29.410
We need to do active equals to true.

03:29.410 --> 03:30.310
I'm sorry.

03:30.310 --> 03:32.290
So yeah how it's going to work.

03:33.310 --> 03:36.550
We have animator and we have Boolean checkpoint active.

03:37.250 --> 03:41.690
Once player enters the trigger, we check if it is active now.

03:41.690 --> 03:47.750
If it's not, then we can proceed with trying to get component of a player and then if player is not

03:47.750 --> 03:50.930
equals to null means player entered the trigger.

03:50.930 --> 03:55.910
And because of that we're going to call the method activate checkpoint which would set active boolean

03:55.910 --> 03:56.510
to true.

03:56.510 --> 04:01.760
Because of that, this would not be able to activate itself again.

04:02.150 --> 04:05.000
And then we would take animator and set.

04:05.590 --> 04:08.860
Value of the parameter to the value of the boolean we have.

04:09.220 --> 04:10.930
So we can play animations.

04:11.880 --> 04:12.510
Yeah.

04:12.510 --> 04:13.980
Let's save this.

04:13.980 --> 04:15.150
Let's go back.

04:16.350 --> 04:17.460
We need to find a checkpoint.

04:17.460 --> 04:19.920
We need to put checkpoint script on it.

04:22.630 --> 04:27.730
And then we need to add a box Collider 2D make it is trigger.

04:27.730 --> 04:31.150
Let's adjust the collider to something like.

04:31.940 --> 04:33.350
So maybe.

04:35.150 --> 04:37.460
Yeah, this should be just fine, I guess.

04:38.670 --> 04:40.740
Then we need animator controller.

04:40.740 --> 04:44.430
Let's go to animations and let's make new one.

04:46.360 --> 04:48.070
Check point.

04:48.310 --> 04:53.440
AC then we're going to take Checkpoint Drug Animator controller over here.

04:53.650 --> 04:56.740
And then we're going to create new clip.

04:56.740 --> 04:57.280
For this.

04:57.280 --> 05:00.610
Make sure you select checkpoint click create.

05:01.380 --> 05:01.830
Over here.

05:01.830 --> 05:02.970
I'm going to do a check.

05:03.760 --> 05:05.950
Check point idol.

05:10.900 --> 05:12.910
And let's go to graphics.

05:13.530 --> 05:15.390
Item checkpoint.

05:16.100 --> 05:20.840
Checkpoint, and let's just drag it here as an idle.

05:20.840 --> 05:22.130
Then let's make.

05:23.610 --> 05:26.610
Checkpoint activated.

05:26.610 --> 05:30.240
And for this one we're going to use this animation over here.

05:30.900 --> 05:32.400
Let's just drag it like so.

05:32.400 --> 05:34.230
Make sample rate 20.

05:36.140 --> 05:38.300
And then we're going to make new clip.

05:39.370 --> 05:40.870
Checkpoint.

05:44.710 --> 05:46.120
Idle active.

05:46.750 --> 05:51.130
And for this one we're going to use this checkpoint with a flag like that.

05:51.130 --> 05:52.750
Sample rate 20.

05:53.080 --> 05:54.820
Now let's go to animator.

05:56.700 --> 05:58.650
Let's select checkpoint.

05:58.650 --> 06:01.590
And over here we want to have checkpoint idle.

06:02.010 --> 06:05.550
Then we need checkpoint activated.

06:06.030 --> 06:08.310
Then checkpoint idle active.

06:08.340 --> 06:10.800
We're going to make one transition here.

06:10.800 --> 06:16.080
If Boolean is true active it should be used.

06:16.080 --> 06:17.370
Trigger parameter.

06:20.390 --> 06:21.830
Because we're not going to transfer back.

06:21.830 --> 06:25.040
So we don't have a reason to check boolean all the time, right?

06:25.040 --> 06:25.550
Yeah.

06:25.550 --> 06:26.990
Let's let's do it.

06:28.030 --> 06:30.580
Let's do trigger activate.

06:30.970 --> 06:31.690
Okay.

06:32.020 --> 06:35.800
So over here we're going to add condition activate.

06:37.010 --> 06:38.390
Let's uncheck exit time.

06:38.390 --> 06:40.250
Transition duration zero.

06:41.560 --> 06:44.950
Then we're going to make another transition to idle active.

06:44.950 --> 06:51.580
And here we're not going to need any condition, but we need exit time one and transition duration zero

06:51.580 --> 06:52.690
just like that.

06:52.690 --> 06:56.110
And then it's going to use this animation and there is no exit from it.

06:57.640 --> 07:04.030
Okay, let's go back and change the parameter to activate.

07:09.140 --> 07:11.000
Okay, I'm going to save it.

07:13.570 --> 07:15.970
And then we're going to try it out.

07:15.970 --> 07:17.290
Let's go to the scene.

07:17.290 --> 07:18.310
To the game.

07:19.570 --> 07:22.390
And I'm going to just try to jump on the checkpoint.

07:28.040 --> 07:28.640
Oh.

07:29.840 --> 07:31.400
Something is wrong.

07:32.680 --> 07:33.100
Let's see.

07:33.100 --> 07:33.820
What is it?

07:36.230 --> 07:36.920
And him.

07:36.920 --> 07:38.570
I did not get animator.

07:39.840 --> 07:40.890
Uh, wake.

07:42.480 --> 07:47.640
Also, you know what this animator is going to be called only once when we activate in checkpoint.

07:48.320 --> 07:54.650
So instead of getting a component, we can do like this get component of animator.

07:54.680 --> 08:00.500
The issue with this is that every time you call an animator, it would try to get component.

08:00.500 --> 08:05.180
And actually when you get in component it takes some, you know, processing power.

08:05.940 --> 08:08.970
And if you just maybe use, uh.

08:10.020 --> 08:17.730
Like for example, if we do random return getcomponent, then every time we use animator in this method,

08:17.730 --> 08:21.810
every time it would get a component every frame, that would be crazy.

08:21.810 --> 08:23.070
That is not okay.

08:23.070 --> 08:27.060
But on a checkpoint when we're doing it only once, I think we can do it this way.

08:27.060 --> 08:27.780
It's fine.

08:28.640 --> 08:30.770
Yeah, and let's save it.

08:37.350 --> 08:38.400
Go to play mode.

08:38.550 --> 08:39.450
Ay yay yay.

08:39.480 --> 08:40.890
We're going to see it now.

08:41.400 --> 08:45.510
I don't know what's up with this, um, error message over here.

08:45.510 --> 08:50.160
I'm getting it only in a new version of unity, and I hope it will be fixed by the time you're doing

08:50.160 --> 08:51.120
this course.

08:53.990 --> 08:55.160
Nice.

08:55.160 --> 08:57.110
Very pretty, I like it.

08:57.170 --> 09:04.790
Now let's actually reassign a position on a game manager when we activate a checkpoint.

09:05.690 --> 09:09.440
So I'm going to go here and I'm going to make.

09:11.070 --> 09:12.360
What we can do here.

09:17.980 --> 09:19.480
I'm going to do public void.

09:20.720 --> 09:24.050
Update respawn position.

09:24.800 --> 09:30.140
And over here, we need to pass a value the same way as we did with a boolean.

09:30.140 --> 09:34.580
We can just make a vector three new position.

09:35.660 --> 09:39.020
And then we would take, uh, sorry, we're not using position.

09:39.020 --> 09:39.860
We're using transform.

09:39.860 --> 09:41.840
So we need to do transform.

09:43.370 --> 09:44.630
Let's do transform.

09:47.180 --> 09:50.510
And let's do a new respawn point.

09:51.080 --> 09:56.570
Then we don't need curly brackets over here because we can do lambda expression and type.

09:56.570 --> 10:01.610
Respawn point is equals to new respawn point just like that.

10:01.880 --> 10:04.070
Now on the checkpoint itself.

10:06.610 --> 10:09.760
When we activate in checkpoint, we're going to call Game Manager.

10:09.790 --> 10:14.470
Game manager dot instance update respawn position.

10:14.470 --> 10:17.410
And as a transform we're going to pass checkpoint itself.

10:17.410 --> 10:19.270
So I'm going to just pass transform.

10:19.930 --> 10:21.040
And save it.

10:23.130 --> 10:26.370
Now we go back and it's supposed to be cool.

10:26.370 --> 10:27.300
Let's go.

10:27.300 --> 10:29.850
Sorry, I got a bit sleepy to do.

10:29.850 --> 10:32.610
Let's go and activate checkpoint.

10:34.040 --> 10:38.840
And we're going to see on the game Manager we've got respawn point checkpoint.

10:39.860 --> 10:41.930
Okay, now let me try to.

10:43.230 --> 10:45.330
Jump into the pit and.

10:45.990 --> 10:47.130
Yes.

10:47.130 --> 10:48.120
Okay.

10:48.390 --> 10:52.590
Now, if you have a couple of them, only the latest one will work.

10:54.370 --> 10:57.910
Let me quickly try that out and we're going to go to the next video.

10:59.670 --> 11:00.630
Um, yeah.

11:01.710 --> 11:02.940
Just like that.

11:05.440 --> 11:06.370
Now it is activated.

11:06.370 --> 11:07.120
I'm going to die.

11:07.120 --> 11:07.990
And.

11:08.900 --> 11:09.350
Here, am I?

11:09.380 --> 11:10.040
Okay.

11:17.680 --> 11:18.520
Very cool.

11:22.950 --> 11:23.730
Okay.

11:23.730 --> 11:26.010
And you cannot activate these checkpoints.

11:26.010 --> 11:27.000
So yeah.

11:27.000 --> 11:27.540
Sorry.

11:27.540 --> 11:30.930
If you want to activate these checkpoints you have to do something about it.

11:30.930 --> 11:31.920
Maybe.

11:32.850 --> 11:34.710
You know, let me just show you the functionality.

11:34.710 --> 11:35.310
Why not?

11:36.250 --> 11:38.260
Let's make a serialized field.

11:38.290 --> 11:42.640
Private bool can be reactivated.

11:42.940 --> 11:45.820
If you have a better name, you can use it and.

11:48.990 --> 11:52.890
We're going to do this and can be reactivated equals to false.

11:52.890 --> 11:57.120
So if this one is false then this if statement still will work.

11:57.120 --> 12:00.780
But if you make it true then it doesn't matter if it is active or not.

12:00.780 --> 12:04.980
You're still going to, uh, activate checkpoint on trigger enter.

12:04.980 --> 12:05.640
Yeah.

12:05.730 --> 12:08.250
And let's go ahead and try this.

12:10.410 --> 12:15.930
Maybe we can make some parameter on a game manager that would tell checkpoints can be reactivated,

12:15.930 --> 12:18.180
but that is not as important right now.

12:18.570 --> 12:19.350
And let's go.

12:22.510 --> 12:23.350
My bed.

12:26.450 --> 12:31.580
So now we can see on the game manager we have checkpoint one is active checkpoint.

12:31.580 --> 12:33.410
Then I'm going to jump to second one.

12:34.190 --> 12:35.780
Now on the game manager.

12:35.780 --> 12:38.000
First checkpoint is a checkpoint.

12:38.000 --> 12:41.570
Now I'm going to go back to the one I had before.

12:42.300 --> 12:44.100
And now in a game manager.

12:46.870 --> 12:49.780
Oh didn't work because it cannot be reactivated.

12:49.780 --> 12:52.210
Let's select them and say can be reactivated.

12:52.210 --> 12:55.210
Okay, game manager, I'm going to see it.

12:56.260 --> 12:56.590
Yeah.

12:56.590 --> 12:57.310
We switched.

12:58.570 --> 13:01.510
So if you want to keep this available, you can do that.

13:01.510 --> 13:02.740
That is up to you.

13:03.990 --> 13:06.180
The last checkpoint you touched would be your checkpoint.

13:07.440 --> 13:09.720
Uh, for me, I'm going to switch it off.

13:09.720 --> 13:10.830
I don't want to have it.

13:10.830 --> 13:14.850
So now let me delete the extra and let's go to assets prefab.

13:14.850 --> 13:16.950
Let's make prefab out of this one.

13:17.250 --> 13:22.590
Also let's go to animations and let's make a folder for checkpoints checkpoint.

13:23.910 --> 13:25.680
And let's drag it here.

13:26.720 --> 13:27.470
Hello, guys.

13:27.470 --> 13:29.180
I made a mistake in a script.

13:29.180 --> 13:32.600
Uh, for some reason, it didn't show me an error, and I did work.

13:32.600 --> 13:33.950
So if you're confused.

13:33.950 --> 13:34.430
Me too.

13:34.430 --> 13:35.360
I'm confused as well.

13:35.360 --> 13:35.570
Why?

13:35.570 --> 13:36.470
It did work.

13:36.470 --> 13:38.330
But anyway, I'm going to show you.

13:38.330 --> 13:39.500
What did I do wrong?

13:39.500 --> 13:41.630
Over here on the animator, we're using trigger.

13:41.630 --> 13:44.330
And in the script I use anim set bool.

13:44.330 --> 13:45.980
And it worked.

13:45.980 --> 13:47.900
So I guess magic.

13:47.900 --> 13:50.060
Nevertheless, I want to be sure it is right.

13:50.060 --> 13:53.990
So I'm going to do set trigger and I'm going to just.

13:54.920 --> 13:55.850
Leave it at that.

13:55.850 --> 13:56.180
Okay?

13:56.180 --> 13:57.590
This is how it's supposed to be.

13:57.620 --> 13:59.360
Uh, thank you so much for paying attention.

13:59.360 --> 14:01.010
And let's go to the next video.
