WEBVTT

00:00.080 --> 00:05.720
We need to link up this maxhealth or basically this help text with our player game object Maxhealth.

00:05.840 --> 00:11.520
So before we do, if we move to canvas, then UI and then choose this help text and then move over to

00:11.560 --> 00:17.080
Inspector, then text component and we can change the text over here something like one, then two,

00:17.120 --> 00:19.280
then three, then four, then five.

00:19.320 --> 00:23.120
Basically what we need, we need a reference of this text component.

00:23.120 --> 00:27.960
Then we can set this number or we can link up with our player Maxhealth.

00:27.960 --> 00:30.760
So we need a reference of this text component.

00:30.760 --> 00:31.720
Then we can do that.

00:31.720 --> 00:33.200
So I'm going to set back to zero.

00:33.360 --> 00:38.720
And let's open up the player script where we just created the maxhealth of our player game object.

00:38.720 --> 00:41.600
So I'm going to select my player game object in the hierarchy.

00:41.600 --> 00:44.520
And let's open up the player script by double clicking on it.

00:44.520 --> 00:47.080
So we're going to we need a reference first.

00:47.080 --> 00:52.360
But before you do make sure you just go to the top of your class and include this namespace.

00:52.360 --> 00:57.160
It's called using Unity engine Unity engine dot UI.

00:57.200 --> 01:02.360
So make sure you just include that because that text component is a UI element.

01:02.360 --> 01:07.840
So that's why whenever we're gonna work with UI we need to include this namespace.

01:08.040 --> 01:10.990
It's called using Unity Unityengine dot UI.

01:11.030 --> 01:12.230
As you can see.

01:12.270 --> 01:16.070
And now we are ready to grab the reference of that text component.

01:16.070 --> 01:18.030
So let's make it public.

01:18.030 --> 01:20.470
And the component will be looking for is a text type.

01:20.470 --> 01:21.910
So we're going to type this text.

01:21.910 --> 01:26.790
And we can simply call this one to something like uh max uh health text.

01:26.790 --> 01:29.070
Or we can simply call it health text.

01:29.070 --> 01:32.830
So let's call it instead health txt or short text.

01:32.830 --> 01:34.790
And we're going to close that up with semicolon.

01:34.790 --> 01:38.350
And let's save script and let's move over to unity.

01:38.350 --> 01:44.150
So underneath our player script we're going to able to see a field will appear and we just name it health

01:44.150 --> 01:44.830
TXT.

01:44.990 --> 01:49.830
So what we need to do right here we need to drag this text game object into that slot.

01:49.870 --> 01:52.710
So we're going to have the reference of that text component.

01:52.710 --> 01:57.550
And then we can just link up with our max health of this player game object.

01:57.550 --> 01:58.070
So what.

01:58.230 --> 01:59.350
Wait for it to compile.

01:59.590 --> 02:02.350
And once it's done we are ready to do that.

02:02.350 --> 02:08.390
So as soon as player script gets compiled we can see health text text and it says text.

02:08.390 --> 02:11.390
So the text is sitting on this health text game object.

02:11.390 --> 02:14.230
So we're going to drag this game object into that slot.

02:14.230 --> 02:15.750
So let's drag it right there.

02:15.750 --> 02:20.470
And now we can see we have health held text.txt component, as you can see.

02:20.470 --> 02:23.950
So basically we have the reference of this text component by now.

02:23.950 --> 02:28.670
And we are ready to set with our max health of this player game object.

02:28.670 --> 02:31.910
So let's open up the player script by double clicking on it.

02:31.910 --> 02:34.550
And we're going to move over to this update function.

02:34.550 --> 02:37.430
Because this update function runs every single frame.

02:37.430 --> 02:43.110
So every single frame we're going to set the text or we're going to update the text according to our

02:43.110 --> 02:44.070
max health.

02:44.070 --> 02:46.550
So what we will do we will go to health text.

02:46.550 --> 02:48.470
And then we're going to access that text.

02:48.470 --> 02:51.350
And we will set equal to our max health.

02:51.350 --> 02:53.430
And we're going to close that up with semicolon.

02:53.430 --> 02:57.070
So the max health over here as you can see this is integer value.

02:57.070 --> 02:58.950
And this one is a string value.

02:58.950 --> 03:01.910
So that's why we are not able to set it directly.

03:01.910 --> 03:06.350
So what we basically need we need to convert this integer value to a string.

03:06.350 --> 03:09.910
So in order to convert that we basically have to type these two string.

03:09.910 --> 03:10.790
And that's it.

03:10.790 --> 03:13.870
And it makes sure you just making this first brackets.

03:13.870 --> 03:18.470
Basically that is a function in order to convert this integer to a string.

03:18.470 --> 03:23.230
So basically what we have done over here we're just going over to Text.txt.

03:23.230 --> 03:27.700
Basically we just going over to this health text and then accessing this text.

03:27.700 --> 03:30.780
And we're setting this text equal to our max cell.

03:30.820 --> 03:31.940
As you can see.

03:31.940 --> 03:34.060
So the max health by default we set five.

03:34.060 --> 03:41.260
So this is gonna be five in the start of the game or once uh basically when our player game uh player

03:41.420 --> 03:43.340
sorry, the game just gonna start.

03:43.340 --> 03:44.940
So the max health just gonna be five.

03:44.940 --> 03:47.100
So this max health is five.

03:47.100 --> 03:49.940
So that's why this health text.txt just gonna be five.

03:49.940 --> 03:52.700
Because as you can see, we directly setting it.

03:52.700 --> 03:57.500
So this is gonna be five right away because, uh, we set max health as five.

03:57.540 --> 04:02.620
So now we're gonna press down control s in order to save our script, and let's move to unity.

04:05.500 --> 04:06.940
And it should be fine.

04:06.940 --> 04:08.900
So let's move over to unity.

04:09.100 --> 04:12.860
And once it's done, we can click on this play button in the top.

04:12.860 --> 04:18.420
And you will see as soon as the game gonna start, the max health will be or this text will be changed

04:18.420 --> 04:20.100
with our max health.

04:20.100 --> 04:24.220
So let's click on this play button in the top and let's have a look on this.

04:24.220 --> 04:30.300
So as soon as the game just gonna start you will see this health text will be updated with our max cell.

04:30.700 --> 04:32.220
So let's have a look on this.

04:32.220 --> 04:38.500
So as you can see as soon as the game started This Celtics just ended with our Maxwell because Maxwell

04:38.500 --> 04:44.620
we set a five and we can see once this a player game object taking damage.

04:44.620 --> 04:46.780
We can see the max health just going down.

04:46.780 --> 04:49.940
And it's stuck at zero as you can see.

04:49.940 --> 04:52.540
So I hope you get the idea that how you can do it.

04:52.540 --> 04:54.300
So I'm going to get out of play mode.

04:54.300 --> 04:59.900
So firstly we're just going over to health Text.txt basically we're just going over to this health text

04:59.900 --> 05:05.180
and then accessing this text component, and we're setting this text equal to our max health.

05:05.180 --> 05:07.460
So in this start of the game max is five.

05:07.460 --> 05:09.940
So this one right over here is five.

05:09.940 --> 05:16.220
So that's why this health text.txt basically this one just gonna be five right away because we directly

05:16.220 --> 05:17.860
setting it as you seen.

05:18.220 --> 05:21.860
So we're going to press down Ctrl s to save our project.

05:21.860 --> 05:29.060
So I hope you get the idea that how you can link up your max cell, uh, or you can link up this text

05:29.060 --> 05:35.620
with the max health of your player game object, and you can do that thing with any game object that

05:35.620 --> 05:37.540
you would like to go with.

05:37.580 --> 05:42.020
Or you can just link anything that you just want to show in your UI.

05:42.220 --> 05:44.700
So you can go and you can do that.
