WEBVTT

00:00.000 --> 00:02.560
We're gonna do the same thing with this heart.

00:02.560 --> 00:07.480
So before we collect the heart, we just want to check off this player back cell.

00:07.600 --> 00:12.520
So if I select my player in the hierarchy, then go over to inspector and then player skip.

00:12.560 --> 00:14.800
We can see the max health of this player.

00:14.800 --> 00:17.320
By default we have given a five.

00:17.480 --> 00:24.040
So if the max of this player game object is already five or greater than five, if that is the case,

00:24.040 --> 00:26.640
then we don't want to collect this heart.

00:26.640 --> 00:31.520
And let's suppose the max health of this player is lesser than five, something like four.

00:31.680 --> 00:33.760
Then we're gonna collect this heart.

00:33.760 --> 00:37.080
So before we collect our heart, we just want to check.

00:38.040 --> 00:38.600
Check.

00:38.600 --> 00:42.200
So what we need we need a reference to our player skip.

00:42.200 --> 00:44.200
Then we can access the max health.

00:44.200 --> 00:46.240
And we're gonna do it inside this player.

00:46.240 --> 00:47.480
Collectible script.

00:47.480 --> 00:49.160
Inside this player collectible.

00:49.160 --> 00:50.960
Skip, we're gonna collect the heart.

00:50.960 --> 00:54.440
And before we collect the heart, we just want to check the max health.

00:54.480 --> 00:57.440
So that's why we need a reference of this player, skip.

00:57.440 --> 00:59.360
And we can access the max cell.

00:59.360 --> 01:04.190
And then we're going to check it To get that, we're going to open up our player collectible script

01:04.190 --> 01:08.950
by double clicking on it in the inspector as and on that script.

01:08.950 --> 01:12.870
And let's go to top of our class and let's grab the reference.

01:12.870 --> 01:16.350
So are we looking for our player Skip.

01:16.350 --> 01:17.670
So we're going to type private.

01:17.670 --> 01:19.190
It doesn't need to be public.

01:19.230 --> 01:25.710
We're going to grab the reference in the start function a function and the component or the script we're

01:25.710 --> 01:27.270
looking for is player.

01:27.270 --> 01:28.910
And we need to name the variable.

01:28.910 --> 01:31.070
So we're going to call it something like player.

01:31.430 --> 01:33.070
And let's go to start function.

01:33.070 --> 01:35.990
So this is start function get call in this start of the game.

01:35.990 --> 01:39.070
So in the start of the game we're just going to grab the reference.

01:39.070 --> 01:44.070
And we can notice that the player script is sitting on this player game object itself.

01:44.070 --> 01:47.230
So that's why we're going to type this start game object.

01:47.270 --> 01:50.990
This dot game object basically means it's just referencing itself.

01:51.190 --> 01:53.990
And now we're going to use this dot get component.

01:53.990 --> 01:56.070
And we need to make this arrows.

01:56.070 --> 01:59.270
So the component we're looking for is our player skip.

01:59.270 --> 02:04.660
So inside these arrows we need to pass our player script name, which is player, and then make this

02:04.660 --> 02:07.620
first bracket and then close that off with semicolon.

02:07.740 --> 02:09.300
Now we have the player script.

02:09.300 --> 02:10.420
And now what we're going to do.

02:10.460 --> 02:13.940
We're going to put this player script into this player script variable.

02:13.980 --> 02:17.500
As you can notice we created up over here.

02:17.500 --> 02:19.900
So I'm going to put it into our player.

02:19.900 --> 02:22.300
So we're going to say player equal to this.

02:22.300 --> 02:26.660
So what we basically doing we just getting we just taking this player script.

02:26.660 --> 02:32.860
As you can see in the Inspector we are taking this player script and we're storing into this player

02:32.860 --> 02:33.780
skip variable.

02:33.820 --> 02:39.220
As you can see right over here in the start of the game we're just setting player equal to this dot

02:39.220 --> 02:39.940
game object.

02:39.940 --> 02:42.220
And the component we're looking for is player.

02:42.700 --> 02:46.060
Or you can simply assume we're just taking that player skip.

02:46.060 --> 02:49.060
And we're storing into this player skip variable.

02:49.060 --> 02:53.380
And now what we're going to do we're gonna uh basically uh check the Maxell.

02:53.420 --> 03:00.820
But before we check, let's, uh, let's do something basically, uh, if we just go over to unity editor,

03:00.940 --> 03:05.050
then a hierarchy, then collectibles, and then choose this game object.

03:05.050 --> 03:06.490
Then go over to Inspector.

03:06.530 --> 03:09.570
As you can notice, we just tag as a heart tag.

03:09.610 --> 03:11.850
As you can notice in Inspector.

03:11.850 --> 03:14.570
So we want to check the check the game object.

03:14.570 --> 03:18.730
If we trigger it with a the game object has a tag called heart.

03:18.770 --> 03:20.490
Then we need to collect that.

03:20.490 --> 03:24.090
And before we collect we need to check the max health of it.

03:24.090 --> 03:28.730
So we will go to our script and we're going to use this Ontriggerenter 2D function.

03:28.730 --> 03:29.130
Why?

03:29.290 --> 03:35.650
Because if we move over to unity a unity and then select this heart game object, then go over to Inspector

03:35.650 --> 03:40.130
Polygon Collider 2D, we can see that we just check this is trigger.

03:40.130 --> 03:45.050
So that's why we're going to use Ontriggerenter 2D function in order to check the trigger.

03:45.050 --> 03:46.610
So we will go to our script.

03:46.610 --> 03:52.450
And over here we're going to do and this function on trigger enter 2D function get called when we trigger

03:52.450 --> 03:53.330
with something.

03:53.330 --> 03:59.170
And we can extract information about what we trigger it with by taking this collision parameter.

03:59.170 --> 04:01.640
So what we're going to do over here we're going to check.

04:01.640 --> 04:06.640
So let's make if a condition and then make this first bracket and some curly brackets.

04:06.640 --> 04:08.600
And what we want to check over here.

04:08.600 --> 04:13.520
We basically want to check if the game object we trigger it with has a tag called hard.

04:13.560 --> 04:15.760
That means we need to collect that hard.

04:15.760 --> 04:17.920
So we're going to use this collision parameter.

04:17.920 --> 04:22.960
So we're going to type collision dot game object and collision dot game object basically means the game

04:23.000 --> 04:24.600
object we trigger it with.

04:24.600 --> 04:27.320
So in our case we're going to trigger with that heart.

04:27.320 --> 04:29.440
So collision dot game object over here.

04:29.480 --> 04:31.520
It's going to be that hard game object.

04:31.520 --> 04:34.560
And now what we're going to do we're going to access the tag of it.

04:34.560 --> 04:36.400
So we're going to type this dot tag.

04:36.440 --> 04:40.040
And we will check if the tag is equals equals to heart.

04:40.640 --> 04:44.920
If that is the case that means we need to collect the heart.

04:44.920 --> 04:47.000
So what we will do over here.

04:47.240 --> 04:51.000
Uh so we need to check before we collect the heart.

04:51.040 --> 04:56.840
We just need to check if the max health of our player game object is already something like five.

04:57.040 --> 05:02.510
So if I select my player game object in the hierarchy, then go over to my player skip in Inspector,

05:02.510 --> 05:05.270
we can notice the max cell is already five.

05:05.270 --> 05:08.750
So if that is the case, that means we don't want to collect.

05:08.750 --> 05:16.430
But if the max cell is something like less than five, uh, some less than five, something like four,

05:16.590 --> 05:18.110
then we just want to collect.

05:18.110 --> 05:22.350
So what we will do, we just want to access the player max cell.

05:22.430 --> 05:23.430
So we will check.

05:23.430 --> 05:28.830
So we're going to use another if condition inside this if and then make this first bracket and some

05:28.830 --> 05:29.870
curly brackets.

05:29.870 --> 05:31.870
And what we want to check over here.

05:31.870 --> 05:37.950
We basically want to check if the max health of this player is lesser than or equal to five.

05:37.950 --> 05:41.790
Something like that, or less than five or equal to five.

05:41.830 --> 05:48.310
If that is the case, then we want to collect our heart, else we're not gonna collect at all.

05:48.430 --> 05:50.510
So we're going to access the max cell.

05:50.510 --> 05:54.510
So what we will do, we do know that we have the player skip, as you can see.

05:54.670 --> 05:58.230
And inside that player skip, we have the max health parameter.

05:58.230 --> 05:59.670
So we're going to access that.

05:59.670 --> 06:02.580
So what we will do we will go to our player.

06:02.580 --> 06:03.060
Skip.

06:03.100 --> 06:05.380
Then we can access Dot Maxell.

06:05.420 --> 06:08.860
But as you can notice, we're not able to access that.

06:08.900 --> 06:09.380
Why?

06:09.580 --> 06:11.900
Because we just marked as serialized field.

06:11.900 --> 06:20.340
We need to mark as public so we can, uh, we can just access that parameter from another class as well.

06:20.340 --> 06:24.580
So what we basically have to do, we need to move over to our player Skip.

06:24.580 --> 06:27.820
And over there we have the maxhealth, as you can notice.

06:27.820 --> 06:32.420
And we just mark as serialized field so we can see underneath our inspector.

06:32.420 --> 06:38.940
So instead of making serialized private we basically need to make this whole thing public or this variable.

06:38.940 --> 06:42.180
So we basically have to type this public int Maxhealth.

06:42.220 --> 06:48.060
And now we can access this parameter from any other from any class that we want.

06:48.060 --> 06:51.500
So we're going to press down Ctrl S to save our player skip.

06:51.540 --> 06:54.580
And now we're gonna move over to Player Collectible Script.

06:54.580 --> 06:57.100
And we are ready to access the Maxhealth.

06:57.140 --> 07:04.650
So what we can simply do by now, we can access player dot dot As you can notice that we can access

07:04.650 --> 07:05.130
the max.

07:05.330 --> 07:09.170
As you can see, if it's less than or equal to five.

07:09.210 --> 07:12.490
If that is the case, then we want to collect our hell.

07:12.810 --> 07:13.850
So I don't know.

07:13.850 --> 07:18.610
We need to pass our five, or we basically can check if it's lesser than five.

07:18.850 --> 07:22.530
If that is the case, then we just want to collect.

07:22.610 --> 07:23.530
So what are we doing?

07:23.530 --> 07:27.290
Firstly, we're checking if we collided with the hard game object or not.

07:27.290 --> 07:29.370
And we're checking if the tag is hard.

07:29.370 --> 07:32.690
And definitely we're gonna trigger with this hard game object.

07:32.850 --> 07:38.970
So if I move over to unity editor and select this hard game object and then go over to Inspector.

07:39.010 --> 07:42.290
As you can notice, we just tag it as a hard tag.

07:42.290 --> 07:46.050
So we just definitely gonna trigger with this hard game object.

07:46.050 --> 07:48.330
As you can notice if that is the case.

07:48.330 --> 07:53.050
And also we're checking if the max health of our player is lesser than five.

07:53.090 --> 07:59.930
If that is the case, that means we need to collect that hard, else we're not gonna collect at all.

07:59.930 --> 08:05.760
So for now, we're gonna print out a message, something like we need to collect our heart.

08:05.760 --> 08:09.600
So we're going to type this debug dot log in order to print out the message.

08:09.600 --> 08:12.520
And we're going to say something like collect heart.

08:12.560 --> 08:15.480
If our max heart collect heart.

08:15.480 --> 08:17.560
And let's close that up with semicolon.

08:17.600 --> 08:25.000
Else if our max health is not lesser than five, lesser than lesser than five basically means our max

08:25.000 --> 08:28.440
health is already something like five or greater than five.

08:28.480 --> 08:31.280
Then we need to stop collecting our heart.

08:31.320 --> 08:37.960
So that's why else if our max health is not lesser than five, means we already have the max health

08:38.000 --> 08:42.120
of our player game object is five, then we don't want to collect.

08:42.120 --> 08:46.440
So that's why we're going to print out a message something like don't collect heart.

08:46.440 --> 08:49.960
So we're going to type this debug.log in order to print out the message.

08:49.960 --> 08:58.600
And we're going to say something like don't, don't collect, collect the heart, something like that.

08:58.600 --> 09:00.920
And we're going to close that off with semicolon.

09:00.920 --> 09:04.190
And we're going to press down Ctrl S to save our skip.

09:04.190 --> 09:06.150
And now we're going to move over to unity.

09:06.350 --> 09:11.390
And you will notice as soon as we're going to trigger with this heart cam object, the mesh is just

09:11.390 --> 09:13.710
going to pop up says don't collect a heart.

09:13.750 --> 09:14.190
Why?

09:14.390 --> 09:18.950
Because the max health of this player object is already five.

09:18.950 --> 09:20.910
So that's why we don't want to collect.

09:20.910 --> 09:25.470
So that's why we just printing out that message with saying don't collect the heart.

09:25.470 --> 09:30.670
So if I select my player game object in a hierarchy, then go over to Inspector player skip.

09:30.710 --> 09:32.830
We can notice the max health is five.

09:32.830 --> 09:37.230
So let's click on this play button in the top in order to play our game.

09:37.230 --> 09:38.990
And let's try to collect this heart.

09:38.990 --> 09:39.870
And you can.

09:40.150 --> 09:44.630
Are you just gonna see that message in our console tab.

09:44.630 --> 09:50.190
Just going to print out something like don't collect heart since we already have the Max health five.

09:50.350 --> 09:56.550
So if I trigger with this heart game object, as you can see, as soon as we trigger, we can see in

09:56.550 --> 10:02.900
our console tab it says don't collect the heart because the max health of this player game object is

10:02.900 --> 10:03.980
already five.

10:03.980 --> 10:10.180
And if we make this max ultra something like four and then trigger with this hard game object, we're

10:10.180 --> 10:16.300
gonna able to notice collect hard up message that's going to pop up since we're checking with our maxhealth

10:16.420 --> 10:18.380
a lesser than five.

10:18.380 --> 10:24.620
So if I trigger by now, we can notice that as soon as we triggering the message is getting pop up in

10:24.620 --> 10:26.700
our console tab, click hard.

10:26.740 --> 10:29.420
Since the maxhealth is not a five.

10:29.460 --> 10:33.700
As you can notice in the inspector underneath our player script.

10:33.980 --> 10:35.460
So the max health is four.

10:35.460 --> 10:38.260
So that's why we want to collect our heart.

10:38.340 --> 10:40.980
And let's suppose the max health is already five.

10:41.020 --> 10:43.300
Then we don't want to collect this heart.

10:43.340 --> 10:45.060
So basically that is the thing.

10:45.460 --> 10:47.820
Uh, so we will get out of play mode.

10:47.940 --> 10:53.420
And now what we need to do instead of printing out message, we basically need to collect this heart.

10:53.980 --> 10:59.380
To do that, we're gonna double click on this message in order to move over to that line of code.

10:59.380 --> 11:03.410
And instead of printing out message, we just want to collect the heart.

11:03.410 --> 11:08.730
And in order to collect the heart, we basically need to increase our max health by one unit.

11:08.890 --> 11:13.010
So we will go to player skip, and then we're going to access the max health.

11:13.010 --> 11:18.170
And top of that we're just going to add one more unit something like plus equal one.

11:18.210 --> 11:24.930
Or you can simply say we're just adding one or you can simply type this plus plus it basically means

11:24.930 --> 11:26.290
you just adding one.

11:26.650 --> 11:31.770
So if the player max health is less than five, let's suppose the player max health is four.

11:32.450 --> 11:37.890
Then what we're doing we just adding as you can notice, player dot max and basically accessing the

11:37.890 --> 11:39.490
max health of our player.

11:39.490 --> 11:42.090
And top of that we just adding one unit.

11:42.090 --> 11:44.210
So four plus one is going to be five.

11:44.210 --> 11:46.490
So the maximum now it's going to be five.

11:46.690 --> 11:52.370
And once it's five then what we need to do we need to play the collected animation clip.

11:52.370 --> 11:57.810
Also we need to disable the Polygon Collider 2d, 2D of this heart game object.

11:57.810 --> 12:03.570
So if I select my heart in the hierarchy underneath my collectibles game object and then go over to

12:03.610 --> 12:04.370
Inspector.

12:04.370 --> 12:11.730
We can notice we assign it heart and we added a collider to the Polygon Collider 2D called Polygon Collider

12:11.770 --> 12:12.330
2D.

12:12.330 --> 12:16.730
So we need to disable as soon as beginner trigger with this heart game object.

12:16.730 --> 12:20.170
So we're not going to able to trigger with two eyes.

12:20.170 --> 12:25.730
So that's why we need to basically we need to disable this polygon collider 2D.

12:25.970 --> 12:32.170
And we also need to destroy are basically we also need to play the heart collected animation clip.

12:32.170 --> 12:37.530
And we do know that that animation clip is sitting on our child heart sprite game object.

12:37.530 --> 12:43.450
So if I select our heart sprite in our underneath our heart game object, then go over to Inspector.

12:43.490 --> 12:48.570
We can notice inside this heart sprite we have this animator component which is sitting.

12:48.770 --> 12:54.690
And if we move over to animator tab, we basically need to trigger this collected parameter.

12:54.690 --> 13:00.290
And basically we doing the same thing as we have done with this fruit game object which is apple.

13:00.290 --> 13:06.440
So we need a reference of this tile game object, that animator component, and we can trigger this

13:06.440 --> 13:12.000
collected parameter and we don't know what we're going to do that it's going to play the collected animation

13:12.000 --> 13:12.520
clip.

13:12.520 --> 13:19.720
So what we need now we basically need to access this sprite uh basically the child game object.

13:19.760 --> 13:25.720
So firstly we will move over to our script and we need to disable the Polygon Collider 2D.

13:25.720 --> 13:30.560
So what we will do we will type this collision game object after collecting the heart.

13:31.000 --> 13:35.200
So collision dot game object basically means the game object we trigger it with.

13:35.200 --> 13:38.440
So we definitely gonna trigger with this heart game object.

13:38.440 --> 13:42.640
So over here collision dot game object basically means that heart game object.

13:42.640 --> 13:47.440
And now what we want to access we want to access the Polygon Collider 2D.

13:47.440 --> 13:49.800
So we're going to type this dot get component.

13:49.800 --> 13:53.280
And the component we're looking for is Polygon Collider 2D.

13:53.440 --> 13:57.320
And make sure you you pass the same component name.

13:57.320 --> 14:03.040
So if I move over to unity editor and then select this heart game object and move over to Inspector

14:03.110 --> 14:07.270
As you can notice, we attach the components of Collider 2D.

14:07.310 --> 14:09.310
It's Polygon Collider 2D.

14:09.310 --> 14:12.350
So we need to make sure we just pass the same thing.

14:12.590 --> 14:14.470
So we're going to move over to script.

14:14.470 --> 14:18.310
And inside these arrows we're going to pass our Polygon Collider 2D.

14:18.350 --> 14:21.030
Basically we just want to access that component.

14:21.030 --> 14:23.710
And we need to make these brackets this first bracket.

14:23.710 --> 14:26.830
And after accessing it we want to access.

14:26.830 --> 14:29.550
Basically we have to type this dot.

14:29.590 --> 14:34.190
And we're going to set enable basically accessing that.

14:34.190 --> 14:36.510
And we're going to set it equal to false.

14:36.510 --> 14:40.110
False basically means we're disabling this polygon collider 2D.

14:40.150 --> 14:43.910
And let's suppose you just pass in dot enable equal to true.

14:43.950 --> 14:49.710
It's basically means that you just enabling your polygon collider 2D since we want to disable.

14:49.710 --> 14:54.630
So that's why firstly we just going over to our hard game object as you can notice.

14:54.630 --> 15:01.550
Then we just going over to our Polygon Collider 2D basically this Polygon Collider 2D and we just are

15:01.550 --> 15:09.460
accessing basically we just using this dot enable in or in order to access that polygon collider 2D

15:09.860 --> 15:15.220
uh, basically this, uh, this and we just setting equal to false basically means we just unchecking

15:15.220 --> 15:16.900
this polygon collider 2D.

15:16.940 --> 15:19.860
Or we can simply say we just disabling that.

15:20.020 --> 15:25.700
And after disabling that what we need to do we basically need to play the animation clip.

15:25.700 --> 15:32.060
And we do know that that uh, collected animation clip, basically the animator component is sitting

15:32.060 --> 15:36.020
on this hard sprite, basically child of this hard game object.

15:36.020 --> 15:37.700
And this will be the first child.

15:37.740 --> 15:42.140
As you can see, hard sprite and the first child index is just gonna be zero.

15:42.140 --> 15:47.820
So what we need to do, we basically want to access the first child, basically that sprite game object.

15:47.980 --> 15:53.580
Uh, to get that we're going to use this collision dot game object and collision dot game object over

15:53.580 --> 15:58.180
here basically means the game object, basically how the hard game object.

15:58.180 --> 16:01.580
And now we're going to use this transform and dot.

16:01.620 --> 16:03.810
We're going to use this get child function.

16:03.810 --> 16:06.850
And the child we're looking for is our heart sprite.

16:06.850 --> 16:09.610
And that heart sprite is our first child.

16:09.610 --> 16:12.010
And first child index is going to be zero.

16:12.010 --> 16:16.690
So inside this bracket we basically have to pass the index which is gonna be zero.

16:16.810 --> 16:19.170
And now we're going to access the game object.

16:19.170 --> 16:20.810
And now we're going to get the component.

16:20.810 --> 16:22.370
So dot get component.

16:22.370 --> 16:28.130
And the component we're looking for is animator which is sitting on our hard sprite game object.

16:28.130 --> 16:32.850
So we're going to type this animator animator and then make this first bracket.

16:32.850 --> 16:36.130
And now we are ready to trigger that collected parameter.

16:36.130 --> 16:41.930
And we do know that if we just trigger that collected parameter it's going to play the animation clip

16:41.930 --> 16:43.410
which is the heart collected.

16:43.410 --> 16:46.930
So we're going to use this dot set trigger function.

16:47.170 --> 16:54.490
And in make this brackets and inside quotation you need to pass the same parameter name.

16:54.610 --> 17:00.890
And if we move over to unity and select this other sprite and then move over to animator tab, we can

17:00.890 --> 17:02.970
see the parameter name is collected.

17:02.970 --> 17:09.120
So make sure inside quotation you pass the parameter name and make sure you spelling it correct.

17:09.160 --> 17:11.400
Else it's not gonna work at all.

17:11.400 --> 17:16.480
So we're going to pass our collected and then close that up with semicolon.

17:16.600 --> 17:21.840
So what we're doing basically firstly we're just going over to our collision dot GameObject basically

17:21.840 --> 17:25.160
means this hard game object as you can see.

17:25.160 --> 17:27.400
Then we're just going over to transform.

17:27.400 --> 17:30.320
So firstly we're just going over to this hard game object.

17:30.320 --> 17:33.880
And then we just are going over to this transform.

17:33.880 --> 17:39.000
And by this transform component we basically accessing accessing the first tile.

17:39.000 --> 17:42.120
Or you can simply say this sprite game object.

17:42.280 --> 17:48.200
And then after going over to hard game object, as you can see we're just getting the animator component.

17:48.240 --> 17:54.600
Basically we're just going over to this sprite, uh, than uh, than this sprite game object, then

17:54.640 --> 18:00.640
going over to this animator component of this sprite, and then we're just triggering this collected

18:00.640 --> 18:03.480
parameter, as you can notice right over here.

18:03.510 --> 18:10.710
So we're just going over to that sprite game object and then accessing the animator as you can notice.

18:10.710 --> 18:15.190
And then we're using dot set trigger function in order to trigger that.

18:15.350 --> 18:20.870
So uh and which is collected as you can see now it's going to play the animation clip.

18:20.870 --> 18:25.830
And we do know that it's the animation just completing after one second.

18:26.350 --> 18:30.510
Basically within one second it just completing the whole animation clip.

18:30.510 --> 18:34.990
So that's why after one second we want to destroy this hard game object.

18:34.990 --> 18:38.070
So we, we want to destroy this hard game object.

18:38.230 --> 18:42.750
After playing the animation clip of this hard game object completely.

18:42.750 --> 18:46.830
And we do know that after one second we just completing, uh, totally.

18:46.830 --> 18:54.790
So that's why are we going to use this destroy function in order to destroy and this as a first argument,

18:54.790 --> 18:57.630
it's going to take the game object that we want to destroy.

18:57.750 --> 19:00.230
So we want to destroy that hard game object.

19:00.230 --> 19:05.900
So we're going to pass our collision dot object basically means the heart game object simply comma.

19:06.020 --> 19:08.060
Second thing, it's going to take the time.

19:08.060 --> 19:14.820
Or if you just don't put the second parameter and you just go ahead and then close that off with semicolon,

19:15.020 --> 19:18.300
then the heart game object just gonna destroy right away.

19:18.300 --> 19:19.660
So we don't want that.

19:19.660 --> 19:23.580
So that's why we just type comma as a second parameter.

19:23.580 --> 19:25.220
We can just pass the time.

19:25.220 --> 19:29.740
And we do know that after one second it just completing the whole animation clip.

19:29.740 --> 19:33.260
So that's why we're going to put one f as a second argument.

19:33.260 --> 19:35.700
And then we're going to close that off with semicolon.

19:35.700 --> 19:40.340
And let's press down Ctrl s on our keyboard in order to save our script.

19:40.580 --> 19:42.820
And now let's move over to unity.

19:42.820 --> 19:48.220
And you will notice as soon as we're going to trigger with this heart game object, it should be collected,

19:48.220 --> 19:50.300
but it's not going to do it all.

19:50.300 --> 19:50.700
Why?

19:50.900 --> 19:52.580
Because we checking the max health.

19:52.580 --> 19:57.740
If it's greater than if it's lesser than then we just collecting else we not doing so.

19:57.740 --> 20:00.500
The message should be pop up in our console tab.

20:00.980 --> 20:05.090
Once we're gonna trigger with this heart game object says stone collect heart.

20:05.130 --> 20:05.650
Why?

20:05.810 --> 20:08.130
Because the Maxwell is already five.

20:08.490 --> 20:14.130
So if I select my console tab and then click on this play button, and you're gonna notice as soon as

20:14.170 --> 20:18.730
we're gonna trigger with this heart game object, or you can simply say collide with this heart game

20:18.770 --> 20:25.170
object, the message just gonna pop up says don't collect heart because we already we already have the

20:25.170 --> 20:27.650
max health of this player game object is five.

20:27.810 --> 20:30.610
So I'm going to select my player game object in the hierarchy.

20:30.650 --> 20:33.250
Then go over to Inspector and then player Skip.

20:33.250 --> 20:37.450
As you can notice, the max health is already zero or sorry already five.

20:37.690 --> 20:43.970
And if we trigger with this heart, as you can see, as soon we trigger it in our console tab, message

20:43.970 --> 20:44.970
just gets pop up.

20:45.010 --> 20:48.370
Don't collect heart because the Maxhealth is already five.

20:48.530 --> 20:53.890
And let's suppose if we make that four and we do know that four is now less than five.

20:54.090 --> 20:57.290
So it basically means we're gonna collect this heart by now.

20:57.290 --> 21:00.570
And the max health which is increasing by one unit.

21:00.570 --> 21:06.400
So if I just collect this heart, as you can see, as soon as we collect it, the Maxwell now becomes

21:06.400 --> 21:14.480
five and the five and the hard game object we can notice it's not anymore in the hierarchy as well as

21:14.480 --> 21:22.280
in the scene view after playing the collected animation clip completely, because we just are destroying

21:22.280 --> 21:23.880
that after one second.

21:23.880 --> 21:27.200
So I hope you get the idea and let me explain one more time.

21:27.200 --> 21:28.920
So I'm going to get out of play mode.

21:28.920 --> 21:35.480
So if I move over to my screen, firstly, firstly we are using this Ontriggerenter 2D function in order

21:35.480 --> 21:39.720
to check with the trigger, and we are checking if the game object that we trigger it.

21:39.760 --> 21:43.160
If that game object has a tag called heart, then what we're doing.

21:43.200 --> 21:44.960
Firstly, we're checking the max health.

21:45.000 --> 21:52.600
If the max cell is less than five of our player, basically means the max health is already five or

21:52.760 --> 21:58.120
less than five, then we collect in and if the max health is already five, then we just printing out

21:58.120 --> 21:59.840
the message in the console tab.

21:59.880 --> 22:02.440
Don't collect the heart as you can notice.

22:02.440 --> 22:05.200
So I hope you get the idea that how you can do it.
