We need to link up this maxhealth or basically this help text with our player game object Maxhealth.
So before we do, if we move to canvas, then UI and then choose this help text and then move over to
Inspector, then text component and we can change the text over here something like one, then two,
then three, then four, then five.
Basically what we need, we need a reference of this text component.
Then we can set this number or we can link up with our player Maxhealth.
So we need a reference of this text component.
Then we can do that.
So I'm going to set back to zero.
And let's open up the player script where we just created the maxhealth of our player game object.
So I'm going to select my player game object in the hierarchy.
And let's open up the player script by double clicking on it.
So we're going to we need a reference first.
But before you do make sure you just go to the top of your class and include this namespace.
It's called using Unity engine Unity engine dot UI.
So make sure you just include that because that text component is a UI element.
So that's why whenever we're gonna work with UI we need to include this namespace.
It's called using Unity Unityengine dot UI.
As you can see.
And now we are ready to grab the reference of that text component.
So let's make it public.
And the component will be looking for is a text type.
So we're going to type this text.
And we can simply call this one to something like uh max uh health text.
Or we can simply call it health text.
So let's call it instead health txt or short text.
And we're going to close that up with semicolon.
And let's save script and let's move over to unity.
So underneath our player script we're going to able to see a field will appear and we just name it health
TXT.
So what we need to do right here we need to drag this text game object into that slot.
So we're going to have the reference of that text component.
And then we can just link up with our max health of this player game object.
So what.
Wait for it to compile.
And once it's done we are ready to do that.
So as soon as player script gets compiled we can see health text text and it says text.
So the text is sitting on this health text game object.
So we're going to drag this game object into that slot.
So let's drag it right there.
And now we can see we have health held text.txt component, as you can see.
So basically we have the reference of this text component by now.
And we are ready to set with our max health of this player game object.
So let's open up the player script by double clicking on it.
And we're going to move over to this update function.
Because this update function runs every single frame.
So every single frame we're going to set the text or we're going to update the text according to our
max health.
So what we will do we will go to health text.
And then we're going to access that text.
And we will set equal to our max health.
And we're going to close that up with semicolon.
So the max health over here as you can see this is integer value.
And this one is a string value.
So that's why we are not able to set it directly.
So what we basically need we need to convert this integer value to a string.
So in order to convert that we basically have to type these two string.
And that's it.
And it makes sure you just making this first brackets.
Basically that is a function in order to convert this integer to a string.
So basically what we have done over here we're just going over to Text.txt.
Basically we just going over to this health text and then accessing this text.
And we're setting this text equal to our max cell.
As you can see.
So the max health by default we set five.
So this is gonna be five in the start of the game or once uh basically when our player game uh player
sorry, the game just gonna start.
So the max health just gonna be five.
So this max health is five.
So that's why this health text.txt just gonna be five.
Because as you can see, we directly setting it.
So this is gonna be five right away because, uh, we set max health as five.
So now we're gonna press down control s in order to save our script, and let's move to unity.
And it should be fine.
So let's move over to unity.
And once it's done, we can click on this play button in the top.
And you will see as soon as the game gonna start, the max health will be or this text will be changed
with our max health.
So let's click on this play button in the top and let's have a look on this.
So as soon as the game just gonna start you will see this health text will be updated with our max cell.
So let's have a look on this.
So as you can see as soon as the game started This Celtics just ended with our Maxwell because Maxwell
we set a five and we can see once this a player game object taking damage.
We can see the max health just going down.
And it's stuck at zero as you can see.
So I hope you get the idea that how you can do it.
So I'm going to get out of play mode.
So firstly we're just going over to health Text.txt basically we're just going over to this health text
and then accessing this text component, and we're setting this text equal to our max health.
So in this start of the game max is five.
So this one right over here is five.
So that's why this health text.txt basically this one just gonna be five right away because we directly
setting it as you seen.
So we're going to press down Ctrl s to save our project.
So I hope you get the idea that how you can link up your max cell, uh, or you can link up this text
with the max health of your player game object, and you can do that thing with any game object that
you would like to go with.
Or you can just link anything that you just want to show in your UI.
So you can go and you can do that.