Instead of having 100, we want to choose a different number, basically a random number.
We just are popping from this anime head game object.
So from this anime one game object, a number just pop up, which is our floating text.
So if I just go ahead and then click on this play button and try to damage this anime -- game object,
you will see the text just getting pop up instead of having a random number.
Let me show you first.
So let's damage damage this anime one game object first.
So let's get closer to this anime one game object.
And if we start damaging, we can see 100 text just getting pop up instead of having a random number.
So what we need.
So we're going to get out of play mode.
For that we need to head over to our floating text game object.
So we will move over to our project tab assets and then prefabs folder.
And we're going to open up the floating text game object by double clicking on it, and if we move over
to hierarchy tab, we can see we have the text, and inside this text mesh component we can see this
is 100.
So instead of having 100 we want to choose a random number.
So we will create a script in order to choose a random number.
So to do that what we will do we'll we will move over to our project tab assets and then script folder.
Let's right click right click there then create.
Then go over to scripting and then click on this Monobehaviour script.
And you can name that script to something like floating script.
So sorry, floating text, something like that.
I already created a floating text script, as you can notice right over here.
So what we simply can do, we can simply select our text game object in the hierarchy and then drag
it, drag this floating text floating text to the add component section in the inspector, or we can
attach that script to this floating text game object as well.
So what we will do, we will select our floating text game object in the hierarchy.
And let's select the floating text script and drag it over to this.
Add component section in the hierarchy and make sure you open it up in prefab mode.
Basically, just go back and then move over to your project tab assets and then prefabs folder and open
up the floating text game object by double clicking on it, and then attach the script to this floating
text game object.
Or you can attach the script to this tape text game object as well.
By clicking on this add component in the inspector, and you can find the script by typing name of the
script, which is in our case floating text.
So we're not gonna attach it twice since I already attached to this floating text game object.
So I'm gonna open that script by double clicking on it.
So let's open that up quickly by double clicking on it and what we will do, we will remove this update
function we don't need as well as we gonna remove this right over here we don't need.
So what we basically need we need a reference to our text mesh.
So if we move over to unity and select this text object underneath our floating text game object, and
if we move over to Inspector then this text mesh component, we can see the number is here which is
100.
So we can set it to something like nine.
As you can see, as soon as we put nine it became nine.
And if we put something like 99 it became 99.
We can put it something like 60.
We can put it 50.
So what we basically need, we need a reference of this text mesh.
Then we can just access this this text and we can just set it to a random number.
So basically that is the thing.
So I'm going to leave with 100.
And let's move over to our script.
So we need a reference to that text mesh.
So let's grab the reference first.
So we will go to top of our class and let's declare a variable which will be serialized, will serialized
field private.
And the component we're looking for is a text mesh.
So we're going to type this text mesh.
And we can call this one text.
Let's call it text.
And let's close that up with semicolon.
And let's create another variable a variable uh to to get a random number.
So we're going to make a another serialized field.
And this will be we're going to make it private.
But we just marked as serialized field.
So we're gonna able to notice underneath our floating text came a floating text script in Inspector.
And we can call this one something like random.
Sorry, it should be random random number.
Let's call it random number, and let's close that up with semicolon.
And now what we're going to do we just getting a little bit.
Sorry.
We need to put in because this is just gonna be type in which will be whole numbers like zero, one,
two, three.
And now we're going to press down Ctrl S in order to save our script.
And let's head over to unity.
So underneath our floating text script we will able to notice it takes a mesh field just gonna pop up.
So what we need to do we basically need to select this text mesh.
And we need to drag it over to that slot.
So we're gonna have the reference.
And after that we can choose a random number.
So if I select my floating text GameObject in the hierarchy, as you can see underneath our floating
text script, we can notice the text and it says none text mesh.
So what we need to do, we need to select the text game object from uh, underneath our this floating
text game object and drag it over to this text field.
So we do know that if we select this text game object underneath our floating text, we can see the
text mesh component is attached to this text game object.
So that's why we need to drag this game object.
So we will have the reference.
So you need to drag the game object in which game object the script is.
Sorry the component is attached.
So in our case this text.
So that's why we drag it there.
And now we can see random number as well.
So we're gonna open up our script by double clicking on it.
And what we will do, we will set our random number equal to random dot random dot range uh random dot
range.
And this random dot range it's going to pick up the minimum inclusive and the maximum include max inclusive.
So we can start with zero not I'm gonna start with zero, I'm gonna start with one.
And I'm gonna put 101.
And now let's close that up with semicolon.
So this random dot range function right over here it's going to pick up a random number between 1 and
1 zero one.
It's not going to pick up 101, but it's definitely gonna pick up 100.
It can be 99 and it's gonna pick up one.
So it can be random number a random number between 1 and 1 zero one.
And what we're doing after picking that number, we're storing that number into this random random number
as you can see.
So we simply selling random number equal to random dot range.
Let's suppose this random dot range function pick up 52.
So this random number right over here it's gonna be 52.
Why.
Because we set it directly, as you can see.
And after that we also need to update in our text mesh.
Basically we need to we need to go over to this text mesh component.
And we need to access this text.
And we're gonna set this text equal to our random number.
So let's move over to our script.
And after that what we will do we will go to text.
Basically, we're just going over to that text message, and we're going to access that text and access
the text.
And we will set equal to our random number.
Sorry.
It should be random random number.
And let's close that up with semicolon.
But we're getting an error.
So this text or text right over here is a let's call it something else.
Instead of calling a text a text let's call it something like text Max.
It's going to be fine.
So let's call let's change it over here as well.
So let's call it text mass.
And now this is fine.
So this text dot text right over here is a string value.
But this random number as you can see right over here is a integer value.
So we need to convert this integer value to a string.
So how we can do that.
We basically have to type this dot two string function and then make this first bracket.
So what we simply doing we just going over to text message and we are accessing the text.
So basically we're just going over to this text and text mesh component.
And then we accessing this text.
And we're setting this text equal to our random number as you can see.
So let's suppose this random dot range function pick up something like 99.
So this random number over here it's going to be 99.
So the random number over here becomes 99.
So the text dot text is going to be 99 because we directly setting it as you can see.
Or you can simply assume that we just updating we just accessing the text of that text mesh component.
And we're setting equal to our random number, as you can notice right over here.
So I hope you get the idea that how you can do it.
And now I'm going to press down Ctrl s on my keyboard in order to save my project.
And let's move over to unity, uh, now.
So that random dot range function just going to pick up a random number between 1 and 1 zero one.
It's not going to pick up 101, but it's definitely just going to pick up 100.
It can be any number between 1 and 1 zero one.
So to go back we will go to hierarchy.
And let's click on this back arrow in order to go back in scene view.
And now if we go ahead and then hit this play button in the top in order to play our game and start
up damaging our enemy one game object, you will see that text just going to pop up.
So just wait.
And if I get closer to this enemy one and now if I damage it, we can see it picks up 100.
So we're getting an error.
So if I pause my game just clicking on this pause button in the top in unity editor and then go over
to console tab, we can see the text mesh have been assigned.
So basically what we have to do, we need to get out of play mode.
And we're gonna move over to our floating text game object.
Basically, we we need to drag the reference so we will head over to our project tab, then assets and
then prefabs folder.
And we will open up our anime sorry floating text game object by double clicking on it.
And if we move over to Inspector we can see underneath our floating text and it says text is none.
Why?
It says none because we recently changed the name.
So that's why we need to drag the reference one more time.
So make sure you just do that.
So the component is sitting on top of this text game.
This game object.
So we're gonna select that and drag it over to this text field.
Now we can see we have the reference and we are ready to get that.
So let's go back and let's click on this play button in the top in order to play our game.
And now if we damage our enemy one we're gonna be able to see a random number between 1 and 1 zero one.
It can be random depending upon one.
One what?
That random dot range function pick up.
So let's get closer to this anime one game object.
And if I damage it.
As you can see, it's became 44.
It's became 77, 81 and nine, 1951, 19 I really apologize, I'm just announcing a little bit weird.
19 and if I just we get 94, we get 41, we get 82.
So it's basically just, uh, getting a random number between 1 and 1 zero one.
So I hope you get the idea that how you can do it.
So I'm gonna get out of play mode and let me explain one more time.
So firstly, what we're doing, we just grabbing the reference as you can see.
And after that we just created a variable in order to just store whatever we get.
So we storing into this random number parameter.
So this random dot range function just going to pick up a random number between one one and 101.
So whatever the number this random dot range function pick up we're storing into this random number
parameter.
As you can notice right over here.
And after that we're just going over to that text mesh component and accessing the text of it.
And then we're setting equal to random number.
So then let's suppose this random dot range function pick up something like 99.
So this random number over here 99.
So this over here becomes 99.
So that's why this text dot text basically we just going over to this this text text mesh component
and then accessing this text.
And we setting equal to a random number.
So we assume it 99.
So that's why this text right over here it's gonna be 99.
So I hope you get the idea that how you can do it.
And.