Instead of spawning the a specific one, we're going to choose a random ground and then we're gonna
spawn it.
So if I move to my project tab, then assets and then prefabs folder, we can see we have multiple ground
and we just drag it into our this grounds array.
As you can see in the inspector underneath our ground spawner script.
So we're going to choose a random one.
And then we're going to spawn that.
So let's open up our script quickly by double clicking on it.
And let's move over to this function.
As you can see over here we just pass uh sorry.
We just pass right over here five, which basically means the sixth ground.
So instead of spawning a specific one we're going to choose a random.
So that's why we just created this private in index variable.
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
uh which ground we just want to spawn.
So that's why we just created this index parameter.
Now what we're going to do.
So before we spawn we're going to choose a random one.
And in order to choose a random number one, we're going to use this random.
So make sure you're just doing as I did over here.
So we're going to use this random dot range function and this random dot range function in brackets.
As a first argument it's going to take the minimum inclusive.
So we're going to pass zero as a first.
And we have to pass the max inclusive as you can see.
So what we're going to pass right over here we're going to pass grounds dot.
Firstly we're going to pass our array name which is grounds.
So we're going to pass round array name.
And then we're going to use dot length.
And then close that up with some my colon.
So let me explain what basically this grant grounds dot length means.
So grant dot length basically means how many crown ground we have.
So if we move over to unity and we can see underneath our spawner script we have 123456789 ten.
So we have 11 grounds.
So that's why this right over here grounds dot length just gonna be 11 right away.
But this random dot range function, it's going to take a number between the zero and the ground dot
length, which is 11.
So it's going to take a random random number between 0 and 11.
But it's not gonna include this ground dot length basically means interval.
It's just gonna include zero and ten between 0 and 10.
It's not gonna include or just gonna pick up 11 something like that.
So this can be this random dot range function.
Just gonna pick up a number between 0 and 11.
But this function it's not gonna pick up 11.
So but it will definitely gonna pick up ten.
Or it can be something like nine.
It can be four.
So this gonna pick up a random number.
So what we're gonna do.
So after pick if this random dot range function just pick up random number something like let's suppose
two and two.
Then we're gonna store the result into this index parameter.
So let's do so whatever the result is.
Basically whatever this random dot range function picks up, we're going to store it into this index
parameter or this index variable variable, which work like as a container you can say.
So we're going to put it in this container.
So in our case index.
So we will set index equal to this.
So this index can be 0123 or even 9 or 10 depending upon what this random dot range function pick ups.
So let's suppose this random dot range range function.
Just pick up something like six.
Then this index is going to be six right away.
Because as you can see we're just setting a index equal to random dot range.
And now what we're going to do we're going to replace this five.
So we're going to replace this five with our this index.
So we're going to pass our index.
And we do know this index can be a random number depending upon what this random dot range function
pick up.
So let's suppose this random dot range function pick up six.
So this is just gonna be six right away.
This index.
So this index over here just became six.
And we just assume it.
So if we move to unity.
So the six index we can see is the seventh ground underneath our ground spawner script as you can see.
So index six is the seven ground basically means this ground number seven just gonna spawn from that
position.
But it can be random.
We do know that we use this random dot range function in order to pick up a random number between zero
and ground.
Stalin means 11.
So it can be random.
So this index can be zero.
So if it's zero then the first ground will be will be spawn from that position.
And let's suppose this random dot range function pick up something like three.
So this index gonna be three.
So this over here will be three.
So grounds three basically means the we can see is the fourth ground.
So let's have a look on this.
So we're going to press down Ctrl S in order to save our script.
And let's move over to unity by now.
And let's have a look.
So we're gonna see a different ground just gonna spawn when we start our game.
But it can be random depending upon what that random dot range function just pick up.
So just wait for to compile and we're gonna play our game in order to check that.
So just wait for to compile.
Just wait for a little moment.
And now what we're gonna do, we're going to click on this play button in the top in order to play our
game.
So let's click on this play button in the top to play our game.
And right after the game start you will see a random or sorry a random ground just gonna spawn.
So let's have a look.
So as soon as the game started we can see.
Now this, uh, I'm gonna click on this pause button in the top in order to pause my game.
And I can see in our hierarchy ground underscore one clone just gets spawn.
So this is the random one.
So we're gonna get out of play mode by clicking on this play button in the top.
And let's click the this play button in the top.
One more time to play our game.
And let's have a look if a random ground is just gonna be spawned.
So let's have a look on this.
So we we have seen the ground one.
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
my game.
And if I move over to hierarchy we can see ground underscore eight.
Clone just gets spawn.
Basically the ground number eight just gets spawn as soon as the game started.
Because in the start of the game we just spawning the ground.
So now let's get out of play mode and what we need to do now we need to change the spawn pose.
Basically, we just want to spawn any ground from next position.
And we do know, as you can see in every ground, we just created this next position.
So that's why we just created an empty game object and we just name it Next Spawn pose.
So what we're going to do now, we're going to spawn the next round, uh, ground from this position.
In order to do that, make sure you assign it with something else.
So we're going to take a look on this in the next chapter.
Or you can say in the next lecture, we're gonna cover this up.