WEBVTT

00:00.120 --> 00:05.800
Instead of spawning the a specific one, we're going to choose a random ground and then we're gonna

00:05.840 --> 00:06.520
spawn it.

00:06.520 --> 00:12.880
So if I move to my project tab, then assets and then prefabs folder, we can see we have multiple ground

00:12.880 --> 00:16.800
and we just drag it into our this grounds array.

00:16.840 --> 00:21.480
As you can see in the inspector underneath our ground spawner script.

00:21.480 --> 00:23.320
So we're going to choose a random one.

00:23.320 --> 00:24.960
And then we're going to spawn that.

00:24.960 --> 00:28.360
So let's open up our script quickly by double clicking on it.

00:28.640 --> 00:30.840
And let's move over to this function.

00:30.840 --> 00:34.080
As you can see over here we just pass uh sorry.

00:34.120 --> 00:39.000
We just pass right over here five, which basically means the sixth ground.

00:39.000 --> 00:43.080
So instead of spawning a specific one we're going to choose a random.

00:43.080 --> 00:46.840
So that's why we just created this private in index variable.

00:46.880 --> 00:52.800
As you can see over here it's just going to keep track of or it's just going to take care of that which

00:53.000 --> 00:55.600
uh which ground we just want to spawn.

00:55.600 --> 00:58.640
So that's why we just created this index parameter.

00:58.680 --> 00:59.760
Now what we're going to do.

00:59.760 --> 01:03.280
So before we spawn we're going to choose a random one.

01:03.480 --> 01:07.760
And in order to choose a random number one, we're going to use this random.

01:07.760 --> 01:10.560
So make sure you're just doing as I did over here.

01:10.560 --> 01:16.120
So we're going to use this random dot range function and this random dot range function in brackets.

01:16.160 --> 01:20.040
As a first argument it's going to take the minimum inclusive.

01:20.040 --> 01:22.480
So we're going to pass zero as a first.

01:22.520 --> 01:27.080
And we have to pass the max inclusive as you can see.

01:27.080 --> 01:31.160
So what we're going to pass right over here we're going to pass grounds dot.

01:31.520 --> 01:34.640
Firstly we're going to pass our array name which is grounds.

01:34.680 --> 01:36.680
So we're going to pass round array name.

01:36.680 --> 01:38.680
And then we're going to use dot length.

01:38.880 --> 01:41.280
And then close that up with some my colon.

01:41.280 --> 01:46.360
So let me explain what basically this grant grounds dot length means.

01:46.560 --> 01:50.520
So grant dot length basically means how many crown ground we have.

01:50.680 --> 02:00.600
So if we move over to unity and we can see underneath our spawner script we have 123456789 ten.

02:00.600 --> 02:02.840
So we have 11 grounds.

02:02.840 --> 02:07.810
So that's why this right over here grounds dot length just gonna be 11 right away.

02:08.090 --> 02:14.250
But this random dot range function, it's going to take a number between the zero and the ground dot

02:14.250 --> 02:15.370
length, which is 11.

02:15.370 --> 02:19.770
So it's going to take a random random number between 0 and 11.

02:19.770 --> 02:24.450
But it's not gonna include this ground dot length basically means interval.

02:24.450 --> 02:28.930
It's just gonna include zero and ten between 0 and 10.

02:29.010 --> 02:33.370
It's not gonna include or just gonna pick up 11 something like that.

02:33.370 --> 02:36.610
So this can be this random dot range function.

02:36.610 --> 02:39.930
Just gonna pick up a number between 0 and 11.

02:39.930 --> 02:42.770
But this function it's not gonna pick up 11.

02:42.770 --> 02:45.690
So but it will definitely gonna pick up ten.

02:45.690 --> 02:47.610
Or it can be something like nine.

02:47.650 --> 02:48.690
It can be four.

02:48.690 --> 02:51.410
So this gonna pick up a random number.

02:51.410 --> 02:52.730
So what we're gonna do.

02:52.730 --> 02:59.290
So after pick if this random dot range function just pick up random number something like let's suppose

02:59.290 --> 03:00.770
two and two.

03:00.810 --> 03:04.170
Then we're gonna store the result into this index parameter.

03:04.170 --> 03:06.570
So let's do so whatever the result is.

03:06.570 --> 03:12.290
Basically whatever this random dot range function picks up, we're going to store it into this index

03:12.290 --> 03:17.570
parameter or this index variable variable, which work like as a container you can say.

03:17.570 --> 03:19.450
So we're going to put it in this container.

03:19.450 --> 03:21.170
So in our case index.

03:21.170 --> 03:23.730
So we will set index equal to this.

03:24.010 --> 03:32.210
So this index can be 0123 or even 9 or 10 depending upon what this random dot range function pick ups.

03:32.210 --> 03:35.610
So let's suppose this random dot range range function.

03:35.610 --> 03:37.370
Just pick up something like six.

03:37.490 --> 03:40.090
Then this index is going to be six right away.

03:40.090 --> 03:45.250
Because as you can see we're just setting a index equal to random dot range.

03:45.410 --> 03:48.330
And now what we're going to do we're going to replace this five.

03:48.370 --> 03:51.570
So we're going to replace this five with our this index.

03:51.570 --> 03:53.290
So we're going to pass our index.

03:53.290 --> 03:59.890
And we do know this index can be a random number depending upon what this random dot range function

03:59.890 --> 04:00.490
pick up.

04:00.490 --> 04:04.010
So let's suppose this random dot range function pick up six.

04:04.010 --> 04:06.330
So this is just gonna be six right away.

04:06.330 --> 04:07.330
This index.

04:07.330 --> 04:10.370
So this index over here just became six.

04:10.370 --> 04:11.890
And we just assume it.

04:11.890 --> 04:13.690
So if we move to unity.

04:13.690 --> 04:20.690
So the six index we can see is the seventh ground underneath our ground spawner script as you can see.

04:20.850 --> 04:27.090
So index six is the seven ground basically means this ground number seven just gonna spawn from that

04:27.090 --> 04:27.810
position.

04:27.810 --> 04:29.170
But it can be random.

04:29.170 --> 04:36.250
We do know that we use this random dot range function in order to pick up a random number between zero

04:36.250 --> 04:37.010
and ground.

04:37.010 --> 04:38.810
Stalin means 11.

04:39.170 --> 04:40.850
So it can be random.

04:40.850 --> 04:42.570
So this index can be zero.

04:42.570 --> 04:47.290
So if it's zero then the first ground will be will be spawn from that position.

04:47.290 --> 04:51.210
And let's suppose this random dot range function pick up something like three.

04:51.210 --> 04:52.650
So this index gonna be three.

04:52.650 --> 04:55.090
So this over here will be three.

04:55.090 --> 04:59.690
So grounds three basically means the we can see is the fourth ground.

04:59.690 --> 05:01.010
So let's have a look on this.

05:01.010 --> 05:04.570
So we're going to press down Ctrl S in order to save our script.

05:04.570 --> 05:06.730
And let's move over to unity by now.

05:06.730 --> 05:07.970
And let's have a look.

05:07.970 --> 05:12.730
So we're gonna see a different ground just gonna spawn when we start our game.

05:12.890 --> 05:19.010
But it can be random depending upon what that random dot range function just pick up.

05:19.210 --> 05:23.570
So just wait for to compile and we're gonna play our game in order to check that.

05:24.130 --> 05:25.690
So just wait for to compile.

05:28.530 --> 05:30.970
Just wait for a little moment.

05:31.410 --> 05:37.650
And now what we're gonna do, we're going to click on this play button in the top in order to play our

05:37.650 --> 05:38.010
game.

05:38.050 --> 05:41.210
So let's click on this play button in the top to play our game.

05:41.330 --> 05:47.450
And right after the game start you will see a random or sorry a random ground just gonna spawn.

05:47.450 --> 05:48.570
So let's have a look.

05:48.770 --> 05:51.490
So as soon as the game started we can see.

05:51.530 --> 05:56.330
Now this, uh, I'm gonna click on this pause button in the top in order to pause my game.

05:56.570 --> 06:02.850
And I can see in our hierarchy ground underscore one clone just gets spawn.

06:02.850 --> 06:04.770
So this is the random one.

06:04.770 --> 06:08.570
So we're gonna get out of play mode by clicking on this play button in the top.

06:08.570 --> 06:11.410
And let's click the this play button in the top.

06:11.410 --> 06:13.090
One more time to play our game.

06:13.210 --> 06:18.940
And let's have a look if a random ground is just gonna be spawned.

06:18.940 --> 06:20.540
So let's have a look on this.

06:20.820 --> 06:23.340
So we we have seen the ground one.

06:23.340 --> 06:28.460
And let's take a look now so we can see I'm going to click on this pause button in the top to pause

06:28.460 --> 06:29.220
my game.

06:29.220 --> 06:33.060
And if I move over to hierarchy we can see ground underscore eight.

06:33.580 --> 06:34.940
Clone just gets spawn.

06:34.940 --> 06:40.180
Basically the ground number eight just gets spawn as soon as the game started.

06:40.180 --> 06:44.180
Because in the start of the game we just spawning the ground.

06:44.180 --> 06:50.580
So now let's get out of play mode and what we need to do now we need to change the spawn pose.

06:50.620 --> 06:54.900
Basically, we just want to spawn any ground from next position.

06:54.900 --> 07:00.500
And we do know, as you can see in every ground, we just created this next position.

07:00.500 --> 07:06.020
So that's why we just created an empty game object and we just name it Next Spawn pose.

07:06.020 --> 07:11.940
So what we're going to do now, we're going to spawn the next round, uh, ground from this position.

07:11.940 --> 07:15.220
In order to do that, make sure you assign it with something else.

07:15.220 --> 07:18.420
So we're going to take a look on this in the next chapter.

07:18.420 --> 07:22.100
Or you can say in the next lecture, we're gonna cover this up.
