WEBVTT

00:00.080 --> 00:05.520
Instead of having 100, we want to choose a different number, basically a random number.

00:05.520 --> 00:09.960
We just are popping from this anime head game object.

00:10.200 --> 00:16.600
So from this anime one game object, a number just pop up, which is our floating text.

00:16.760 --> 00:22.960
So if I just go ahead and then click on this play button and try to damage this anime -- game object,

00:23.000 --> 00:29.320
you will see the text just getting pop up instead of having a random number.

00:29.360 --> 00:30.440
Let me show you first.

00:30.440 --> 00:34.600
So let's damage damage this anime one game object first.

00:34.680 --> 00:38.320
So let's get closer to this anime one game object.

00:38.320 --> 00:45.960
And if we start damaging, we can see 100 text just getting pop up instead of having a random number.

00:46.040 --> 00:47.120
So what we need.

00:47.120 --> 00:48.800
So we're going to get out of play mode.

00:48.800 --> 00:52.720
For that we need to head over to our floating text game object.

00:52.720 --> 00:57.400
So we will move over to our project tab assets and then prefabs folder.

00:57.400 --> 01:02.770
And we're going to open up the floating text game object by double clicking on it, and if we move over

01:02.770 --> 01:09.130
to hierarchy tab, we can see we have the text, and inside this text mesh component we can see this

01:09.130 --> 01:10.130
is 100.

01:10.130 --> 01:14.210
So instead of having 100 we want to choose a random number.

01:14.210 --> 01:18.290
So we will create a script in order to choose a random number.

01:18.290 --> 01:25.770
So to do that what we will do we'll we will move over to our project tab assets and then script folder.

01:25.770 --> 01:28.770
Let's right click right click there then create.

01:28.810 --> 01:32.690
Then go over to scripting and then click on this Monobehaviour script.

01:32.730 --> 01:35.970
And you can name that script to something like floating script.

01:35.970 --> 01:39.570
So sorry, floating text, something like that.

01:39.570 --> 01:45.330
I already created a floating text script, as you can notice right over here.

01:45.330 --> 01:51.250
So what we simply can do, we can simply select our text game object in the hierarchy and then drag

01:51.250 --> 01:58.470
it, drag this floating text floating text to the add component section in the inspector, or we can

01:58.470 --> 02:02.230
attach that script to this floating text game object as well.

02:02.230 --> 02:07.070
So what we will do, we will select our floating text game object in the hierarchy.

02:07.310 --> 02:10.750
And let's select the floating text script and drag it over to this.

02:10.790 --> 02:15.870
Add component section in the hierarchy and make sure you open it up in prefab mode.

02:15.910 --> 02:22.190
Basically, just go back and then move over to your project tab assets and then prefabs folder and open

02:22.190 --> 02:27.990
up the floating text game object by double clicking on it, and then attach the script to this floating

02:28.030 --> 02:29.150
text game object.

02:29.150 --> 02:33.310
Or you can attach the script to this tape text game object as well.

02:33.350 --> 02:39.630
By clicking on this add component in the inspector, and you can find the script by typing name of the

02:39.630 --> 02:42.350
script, which is in our case floating text.

02:42.350 --> 02:47.750
So we're not gonna attach it twice since I already attached to this floating text game object.

02:47.750 --> 02:51.550
So I'm gonna open that script by double clicking on it.

02:51.550 --> 02:58.320
So let's open that up quickly by double clicking on it and what we will do, we will remove this update

02:58.320 --> 03:03.720
function we don't need as well as we gonna remove this right over here we don't need.

03:03.720 --> 03:07.920
So what we basically need we need a reference to our text mesh.

03:07.920 --> 03:14.360
So if we move over to unity and select this text object underneath our floating text game object, and

03:14.360 --> 03:20.560
if we move over to Inspector then this text mesh component, we can see the number is here which is

03:20.560 --> 03:21.320
100.

03:21.320 --> 03:23.400
So we can set it to something like nine.

03:23.440 --> 03:26.960
As you can see, as soon as we put nine it became nine.

03:26.960 --> 03:30.800
And if we put something like 99 it became 99.

03:30.880 --> 03:33.120
We can put it something like 60.

03:33.160 --> 03:34.640
We can put it 50.

03:34.760 --> 03:38.320
So what we basically need, we need a reference of this text mesh.

03:38.320 --> 03:43.880
Then we can just access this this text and we can just set it to a random number.

03:43.880 --> 03:45.400
So basically that is the thing.

03:45.400 --> 03:46.960
So I'm going to leave with 100.

03:47.120 --> 03:48.960
And let's move over to our script.

03:48.960 --> 03:51.640
So we need a reference to that text mesh.

03:51.640 --> 03:53.530
So let's grab the reference first.

03:53.530 --> 04:01.330
So we will go to top of our class and let's declare a variable which will be serialized, will serialized

04:01.330 --> 04:03.130
field private.

04:03.130 --> 04:06.170
And the component we're looking for is a text mesh.

04:06.170 --> 04:08.250
So we're going to type this text mesh.

04:08.570 --> 04:10.770
And we can call this one text.

04:10.810 --> 04:11.930
Let's call it text.

04:11.930 --> 04:14.330
And let's close that up with semicolon.

04:14.330 --> 04:21.290
And let's create another variable a variable uh to to get a random number.

04:21.290 --> 04:23.890
So we're going to make a another serialized field.

04:24.090 --> 04:27.050
And this will be we're going to make it private.

04:27.050 --> 04:29.210
But we just marked as serialized field.

04:29.210 --> 04:35.970
So we're gonna able to notice underneath our floating text came a floating text script in Inspector.

04:36.210 --> 04:39.450
And we can call this one something like random.

04:39.850 --> 04:44.090
Sorry, it should be random random number.

04:44.410 --> 04:48.530
Let's call it random number, and let's close that up with semicolon.

04:48.530 --> 04:52.070
And now what we're going to do we just getting a little bit.

04:52.110 --> 04:52.750
Sorry.

04:52.790 --> 04:59.230
We need to put in because this is just gonna be type in which will be whole numbers like zero, one,

04:59.230 --> 04:59.950
two, three.

04:59.990 --> 05:03.550
And now we're going to press down Ctrl S in order to save our script.

05:03.550 --> 05:05.230
And let's head over to unity.

05:05.430 --> 05:11.870
So underneath our floating text script we will able to notice it takes a mesh field just gonna pop up.

05:11.870 --> 05:15.230
So what we need to do we basically need to select this text mesh.

05:15.230 --> 05:17.990
And we need to drag it over to that slot.

05:17.990 --> 05:19.430
So we're gonna have the reference.

05:19.430 --> 05:22.350
And after that we can choose a random number.

05:22.630 --> 05:28.110
So if I select my floating text GameObject in the hierarchy, as you can see underneath our floating

05:28.150 --> 05:33.790
text script, we can notice the text and it says none text mesh.

05:33.790 --> 05:40.150
So what we need to do, we need to select the text game object from uh, underneath our this floating

05:40.190 --> 05:43.510
text game object and drag it over to this text field.

05:43.750 --> 05:49.560
So we do know that if we select this text game object underneath our floating text, we can see the

05:49.560 --> 05:53.040
text mesh component is attached to this text game object.

05:53.040 --> 05:55.400
So that's why we need to drag this game object.

05:55.400 --> 05:57.000
So we will have the reference.

05:57.000 --> 06:01.320
So you need to drag the game object in which game object the script is.

06:01.440 --> 06:03.400
Sorry the component is attached.

06:03.400 --> 06:05.120
So in our case this text.

06:05.240 --> 06:07.080
So that's why we drag it there.

06:07.240 --> 06:09.920
And now we can see random number as well.

06:09.920 --> 06:13.400
So we're gonna open up our script by double clicking on it.

06:13.400 --> 06:24.840
And what we will do, we will set our random number equal to random dot random dot range uh random dot

06:24.880 --> 06:25.520
range.

06:25.520 --> 06:34.000
And this random dot range it's going to pick up the minimum inclusive and the maximum include max inclusive.

06:34.000 --> 06:39.360
So we can start with zero not I'm gonna start with zero, I'm gonna start with one.

06:39.360 --> 06:41.440
And I'm gonna put 101.

06:41.440 --> 06:43.880
And now let's close that up with semicolon.

06:43.880 --> 06:50.110
So this random dot range function right over here it's going to pick up a random number between 1 and

06:50.110 --> 06:51.340
1 zero one.

06:51.380 --> 06:56.020
It's not going to pick up 101, but it's definitely gonna pick up 100.

06:56.060 --> 06:58.900
It can be 99 and it's gonna pick up one.

06:58.900 --> 07:04.460
So it can be random number a random number between 1 and 1 zero one.

07:04.460 --> 07:11.660
And what we're doing after picking that number, we're storing that number into this random random number

07:11.660 --> 07:12.860
as you can see.

07:12.860 --> 07:16.700
So we simply selling random number equal to random dot range.

07:16.740 --> 07:20.820
Let's suppose this random dot range function pick up 52.

07:20.860 --> 07:24.540
So this random number right over here it's gonna be 52.

07:24.580 --> 07:24.980
Why.

07:25.140 --> 07:27.860
Because we set it directly, as you can see.

07:28.020 --> 07:31.380
And after that we also need to update in our text mesh.

07:31.420 --> 07:35.580
Basically we need to we need to go over to this text mesh component.

07:35.580 --> 07:37.340
And we need to access this text.

07:37.340 --> 07:41.420
And we're gonna set this text equal to our random number.

07:41.420 --> 07:43.620
So let's move over to our script.

07:43.620 --> 07:46.470
And after that what we will do we will go to text.

07:46.510 --> 07:52.110
Basically, we're just going over to that text message, and we're going to access that text and access

07:52.110 --> 07:52.630
the text.

07:52.630 --> 07:56.230
And we will set equal to our random number.

07:56.630 --> 07:57.110
Sorry.

07:57.390 --> 08:00.470
It should be random random number.

08:00.470 --> 08:02.510
And let's close that up with semicolon.

08:02.510 --> 08:04.310
But we're getting an error.

08:04.310 --> 08:08.830
So this text or text right over here is a let's call it something else.

08:08.870 --> 08:13.590
Instead of calling a text a text let's call it something like text Max.

08:13.630 --> 08:14.790
It's going to be fine.

08:14.790 --> 08:18.110
So let's call let's change it over here as well.

08:18.310 --> 08:20.270
So let's call it text mass.

08:20.430 --> 08:21.710
And now this is fine.

08:21.750 --> 08:25.550
So this text dot text right over here is a string value.

08:25.550 --> 08:30.510
But this random number as you can see right over here is a integer value.

08:30.510 --> 08:33.710
So we need to convert this integer value to a string.

08:33.710 --> 08:34.950
So how we can do that.

08:34.950 --> 08:40.150
We basically have to type this dot two string function and then make this first bracket.

08:40.430 --> 08:45.400
So what we simply doing we just going over to text message and we are accessing the text.

08:45.400 --> 08:49.680
So basically we're just going over to this text and text mesh component.

08:49.680 --> 08:52.120
And then we accessing this text.

08:52.120 --> 08:56.840
And we're setting this text equal to our random number as you can see.

08:57.160 --> 09:01.640
So let's suppose this random dot range function pick up something like 99.

09:01.640 --> 09:05.160
So this random number over here it's going to be 99.

09:05.160 --> 09:08.600
So the random number over here becomes 99.

09:08.600 --> 09:14.400
So the text dot text is going to be 99 because we directly setting it as you can see.

09:14.440 --> 09:20.960
Or you can simply assume that we just updating we just accessing the text of that text mesh component.

09:20.960 --> 09:26.080
And we're setting equal to our random number, as you can notice right over here.

09:26.080 --> 09:29.000
So I hope you get the idea that how you can do it.

09:29.000 --> 09:34.240
And now I'm going to press down Ctrl s on my keyboard in order to save my project.

09:34.240 --> 09:37.040
And let's move over to unity, uh, now.

09:37.400 --> 09:44.180
So that random dot range function just going to pick up a random number between 1 and 1 zero one.

09:44.220 --> 09:48.940
It's not going to pick up 101, but it's definitely just going to pick up 100.

09:48.980 --> 09:52.580
It can be any number between 1 and 1 zero one.

09:52.940 --> 09:55.180
So to go back we will go to hierarchy.

09:55.180 --> 09:59.100
And let's click on this back arrow in order to go back in scene view.

09:59.340 --> 10:07.020
And now if we go ahead and then hit this play button in the top in order to play our game and start

10:07.020 --> 10:13.180
up damaging our enemy one game object, you will see that text just going to pop up.

10:13.180 --> 10:14.100
So just wait.

10:14.780 --> 10:21.540
And if I get closer to this enemy one and now if I damage it, we can see it picks up 100.

10:21.980 --> 10:23.460
So we're getting an error.

10:23.460 --> 10:29.460
So if I pause my game just clicking on this pause button in the top in unity editor and then go over

10:29.460 --> 10:34.380
to console tab, we can see the text mesh have been assigned.

10:34.500 --> 10:37.700
So basically what we have to do, we need to get out of play mode.

10:37.980 --> 10:41.430
And we're gonna move over to our floating text game object.

10:41.470 --> 10:47.950
Basically, we we need to drag the reference so we will head over to our project tab, then assets and

10:47.950 --> 10:49.390
then prefabs folder.

10:49.390 --> 10:54.670
And we will open up our anime sorry floating text game object by double clicking on it.

10:54.910 --> 11:01.430
And if we move over to Inspector we can see underneath our floating text and it says text is none.

11:01.470 --> 11:01.830
Why?

11:01.870 --> 11:04.910
It says none because we recently changed the name.

11:04.910 --> 11:08.270
So that's why we need to drag the reference one more time.

11:08.270 --> 11:09.910
So make sure you just do that.

11:09.910 --> 11:13.830
So the component is sitting on top of this text game.

11:14.190 --> 11:15.430
This game object.

11:15.430 --> 11:18.950
So we're gonna select that and drag it over to this text field.

11:18.990 --> 11:23.670
Now we can see we have the reference and we are ready to get that.

11:23.910 --> 11:29.270
So let's go back and let's click on this play button in the top in order to play our game.

11:29.390 --> 11:36.830
And now if we damage our enemy one we're gonna be able to see a random number between 1 and 1 zero one.

11:36.830 --> 11:39.800
It can be random depending upon one.

11:40.200 --> 11:41.120
One what?

11:41.160 --> 11:43.720
That random dot range function pick up.

11:43.720 --> 11:46.720
So let's get closer to this anime one game object.

11:46.720 --> 11:47.760
And if I damage it.

11:47.760 --> 11:49.920
As you can see, it's became 44.

11:50.040 --> 12:00.960
It's became 77, 81 and nine, 1951, 19 I really apologize, I'm just announcing a little bit weird.

12:02.680 --> 12:10.360
19 and if I just we get 94, we get 41, we get 82.

12:10.400 --> 12:16.640
So it's basically just, uh, getting a random number between 1 and 1 zero one.

12:16.640 --> 12:19.240
So I hope you get the idea that how you can do it.

12:19.240 --> 12:23.440
So I'm gonna get out of play mode and let me explain one more time.

12:23.440 --> 12:27.440
So firstly, what we're doing, we just grabbing the reference as you can see.

12:27.520 --> 12:33.200
And after that we just created a variable in order to just store whatever we get.

12:33.200 --> 12:36.900
So we storing into this random number parameter.

12:36.900 --> 12:43.500
So this random dot range function just going to pick up a random number between one one and 101.

12:43.500 --> 12:50.140
So whatever the number this random dot range function pick up we're storing into this random number

12:50.140 --> 12:50.860
parameter.

12:50.980 --> 12:53.380
As you can notice right over here.

12:53.380 --> 12:58.740
And after that we're just going over to that text mesh component and accessing the text of it.

12:58.740 --> 13:01.420
And then we're setting equal to random number.

13:01.420 --> 13:05.780
So then let's suppose this random dot range function pick up something like 99.

13:05.780 --> 13:09.060
So this random number over here 99.

13:09.060 --> 13:11.460
So this over here becomes 99.

13:11.460 --> 13:20.220
So that's why this text dot text basically we just going over to this this text text mesh component

13:20.220 --> 13:21.860
and then accessing this text.

13:21.860 --> 13:24.660
And we setting equal to a random number.

13:24.660 --> 13:26.500
So we assume it 99.

13:26.500 --> 13:30.420
So that's why this text right over here it's gonna be 99.

13:30.420 --> 13:33.060
So I hope you get the idea that how you can do it.

13:33.340 --> 13:33.860
And.
