Once we trigger with that box Collider 2D, then we're going to spawn the next round.
So if I select my ground underscore six GameObject underneath my hierarchy, as you can see we attach
this box Collider 2D.
And we just if we move over to this box Collider 2D in the Inspector, we can see we just take this
trigger to true.
So once we trigger with this box Collider 2D, then we're going to spawn the next one.
So that's why we attach.
And also we have created a next spawn pose over here as you can see.
So we're going to spawn the next round from this position.
So basically that is the thing.
So let's do that.
So I'm going to select my spawner game object in my hierarchy.
And let's open up the ground spawner script by double clicking on it.
And what we need to do before we just trigger with that and then spawn.
We're going to change this spawn pose as you can see.
So we basically want to spawn the next round from this position.
So that's why we just created this next spawn position or this empty game object.
So we're going to spawn the next from here.
Next round from here.
So that's why we're going to change the position as well.
So before we spawn our ground we're going to change the position.
So which is next spawn post.
So we're going to type next.
Next is spawn post or next spawn position.
And we're going to set equal to.
We're going to set a equal to game object.
So what we basically want to do.
So we basically need to remove this.
Basically I'm really sorry.
We need to do it over here instead of doing there.
So we as you can see we just spawning our this ground at this position with no rotation as you can see.
So after spawning this ground, what we're going to do, we're going to store this ground into another
game object.
Or you can simply say into another container.
So we spawning this ground at this position with no rotation, as you can see.
And after spawning we're going to store this ground into another container.
Or you can simply say into another game object and that will be game object type Y.
Basically this itself a game object.
So that's why.
So after spawning this game object, we just want to store this game object or this ground into this,
this game object container.
And we have to name the container or where we want to store it.
We have to name it.
So I'm going to call it something like temp ground.
Or you can simply say temporary ground.
And I'm going to set equal to this.
So firstly we spawn it at this position with no rotation as you can see.
And after that we just taking whatever we spawn it.
So we definitely gonna spawn this ground.
So after spawning we just taking that ground and we storing into this temp ground container.
You can simply say as you can see.
So firstly we spawn it and after that we just store this spawn ground or the ground or the ground that
we spawn it.
We just taking that and we just say storing into this same ground.
As you can see.
So we just um, we basically doing GameObject temp ground and we setting equal to this.
So I hope you get the idea.
And after that what we need to do, we need to change this spawn pose.
Basically we just want to spawn the next round from this position.
So that's why we need to change this next spawn pose position as well.
So what we're going to do we're going to set next spawn pose equal to.
We will go to this temp crown basically to that container you can simply say or where we store it our
ground.
So we store it in this temp ground.
So we're just going over to that game object basically where we store it.
And then we're going to get the transform component and we will get the child.
So we're going to use this dot get child function and this function over here, it's going to take the
child.
Which child you just looking for.
So basically what we want to do if we select my ground underscore game object in the hierarchy and then
click over here we can see we just created this next spawn post.
So our this next position as you can see.
So the next position basically means is is second child of this ground underscore six game object.
So zero basically means the first child which is green.
And we don't want to we actually not looking for this.
Instead we're looking for the second child.
Or you can simply say the next position.
So the second child of this ground underscore six game object or the add or any of those ground just
going to be this one, which the second child is gonna be this one.
So we need to pass one one basically referencing the second child or the game object or the position
we're looking for.
So we're gonna look for this next position.
So this next position basically means the second child.
And the index of it is going to be one one.
Basically just going to reference a reference the second child.
So let's go to script now.
So we're going to pass one means the second child.
And then we're going to go to the transform component of that game object.
And then accessing.
Or we can access the position dot position and close that up with semicolon.
So basically we're just taking the position and we're just storing that position into this next spawn
pose.
So let me explain.
So we just go moving over to this same ground train.
Ground basically means the uh where we started our ground after spawning.
So we spawn this ground and then we just store it into this temp ground.
So then after that, what we're doing, we're just going over to ten gram transform.
So let's suppose we just, uh, is we gonna assume that we spawn this ground underscore six game object.
So basically what we're doing, we're just going over to this game object transform component in the
inspector.
As you can see, and by this transform component we just accessing the second child.
So in our case we're just accessing the next position.
And we do know that next position uh index basically means the one.
And after accessing the child, as you can see we're just going to that child game object transform
component and then accessing the position.
So basically we're just going over to this next spawn post position and then accessing the transform
of this.
As you can see in the inspector.
And after that we just accessing the position.
And we're storing this position into this next spawn post as you can see over here.
So basically uh, basically the ground just gonna spawn from that position.
And we just stored the position into this next spawn post which has x axis and y axis.
And this also gonna have the x axis x axis as you can see in the inspector.
And we can ignore the z axis.
So so basically that is the thing.
And we're going to press down control S in order to save our script.
And let's move over to unity.
You will see that, uh, the next ground just going to spawn from this position, uh, from this next
spawn position.
So I'm going to remove, uh, that, uh, basically that thing.
Just wait.
And we also need to call this function.
But when we should uh, when we should call this function, once we trigger uh, enter with that box
collider.
So let me explain one more time.
So if we select this ground underscore one game six game object, we can see we just added a box collider.
Uh, so once this player game object collide with this box Collider or just enter it inside this box
Collider 2D, then we just want to spawn the next one.
Uh, next one.
So that's why we're going to call the function once we trigger with this box.
So we're going to open up our player script.
So let's select the player GameObject in the hierarchy.
And let's open up the player script in the Inspector by double clicking on it.
And we're going to do it.
Uh, we're going to use a function for that.
So let's do it in the bottom.
You can do it anywhere.
It doesn't need to be in order.
So we're going to use this on trigger.
On trigger enter 2D.
So make sure uh you do that as I did over here as you can see.
So this function get called when we trigger with something.
So let's suppose this player game object just trigger with this ground underscore six game object box
collider 2D.
Then this function right over here is just gonna get called.
And we can extract info what we collided with by going over to this collision parameter, something
like we can extract info the game object, we trigger it with uh like name of the game object or the
component.
We're looking for even the tag of the game object.
So we're going to access the tag of this box Collider 2D.
And we're going to check if the tag is box.
And we do know we assigned this box Collider 2D or this ground underscore six six GameObject box Collider
2D as a box tag.
As you can see in the inspector.
So we're going to check that.
So let's move to script.
So this function get called when we trigger with something.
Or we just enter it inside this box Collider 2D.
So this function over here just gonna get called.
And we're going to check whatever we trigger it with or whatever.
We just gets inside.
We're gonna check off the GameObject tag.
So we're going to use this if condition.
So make first bracket and some curly brackets.
So what we want to check over here in this in between these brackets we're going to move over to this
collision.
So we're going to use this collision parameter in order to check.
So we're going to use this collision then dot GameObject.
Then we're going to access the tag.
And we will check if the tag is equals equals to box.
So box.
So then what we're going to do we're going to spawn our ground.
Uh for now let's print out a message, and later on, we're gonna spawn the ground.
So we're gonna type debug log, debug dot log and make first bracket in quotation.
You can type the message that you just want to see underneath your console tab.
So I'm going to call it something like spawn ground spawn ground.
And let's close that up with semicolon.
So what we're doing we're just taking whatever we triggered with.
So collision dot game object basically means the game object we trigger it with.
So if this player game object collided or triggered it with this box collider 2D then collision dot
game object.
They are just gonna be this box Collider 2D or this.
You can simply say this ground underscore six game object basically means we just trigger it with this.
And then what we're doing we just accessing the tag of the game object.
So this player game object just trigger it with this box.
Collider 2D means our this ground underscore six game object.
And what we're doing we just accessing the tag of this game object.
As you can see, we just assign it this ground underscore six game object as a box tag.
As you can see in the inspector.
So we just accessing the tag which is box.
And we check it checking if the text is equals equals to box.
As you can see.
So we definitely gonna trigger with this box game object.
And we do know we assign it this ground underscore six box Collider 2D as a box tag.
So we're definitely gonna trigger with this.
Then what are we doing.
As you can see we just printing out a message in the console says Spawn ground.
So whenever we're gonna trigger or will, uh, will, uh, we gonna get inside of this box Collider
2D or we trigger with this box Collider 2D of this ground underscore six game object.
Then this message just gonna pop up in the console right away.
So I'm gonna press down Ctrl s in order to save our script.
And let's move to unity.
So just wait a little moment.
So once we're gonna get inside of this box, Collider 2D of this ground underscore six game object,
that match is just going to pop up.
So let's select the console tab and let's click on this play button in the top in order to see our the
message that we just printed out in the console.
So as you can see, as soon as we trigger it with this box, Collider 2D or gets inside of this box
Collider 2D, uh, of this ground underscore six game object, we can see a in the console spawn ground
message just gets pop up.
So what we're going to do now we're going to get out of play mode.
So let's get out of play mode.
Instead of printing out message what we want we just want to spawn our ground.
So we're going to double click on this message in order to go to that line of code.
And instead of printing out message we're going to call this spawn ground function.
And we do know what we're doing inside that function, which is spawning the next round.
So we're going to make this double forward slash in order to make this comment.
And we do no comment.
Just don't interrupt our code and what we will do.
We're going to use this find uh find any object by type.
So make sure you just using this and you need to make this arrows.
Uh so find any object of by type and into arrows.
We need to pass the script name or the game object we're looking for.
So we do know inside this ground spawner script, we just created this spawn ground function.
And this function just doing the rest thing which is spawning our ground from that next position.
So basically what we need, we need to call this spawn ground function in order to spawn our ground.
And we have it inside this ground spawner script as you can see.
So we need to move over to this script first.
And then we're going to access the this spawn ground function.
So let's go to player skip.
So when we trigger it with uh so what we're doing, we're just using this.
Find any object by type and into arrows.
We need to pass the script name for which script we're just looking for.
So in our case ground spawner.
So we're going to type this ground spawner script.
And then you need to make this first bracket.
And inside that ground spawner script we just created that is ground sorry ground spawner function as
you seen.
So we're going to call the function over here.
So we're going to use this dot and spawn ground and make first bracket.
And then we're going to close that up with semicolon.
So let me explain one more time what we have done over here.
Firstly we're just going over to that ground spawner script and then calling the function.
As you can see.
And when we're just calling this once we trigger it with that box collide box Collider or that box tag
as you can see.
So basically we're just going over to this ground spawner script.
Uh, then we just simply calling this spawn ground function and spawn coupon grants function doing this
thing, which is just spawning the next one from that next position.
So let's go to our player script and we're going to press down control S in order to save our script
and head over to unity by now.
And let's have a look.
So as soon as we're going to trigger with that box Collider 2D of this ground underscore six game object,
you will see the next round.
Just gonna spawn from that next position.
So let's have a look on this.
So let's click on this play button in the top.
As soon as we're going to collide with this uh box you will see the next ground.
Just gonna spawn from that next position.
So as you can see, as soon as we trigger it, we can see that this ground just gets spawned from that
next position.
So I'm going to click on this pause button in the top in order to pause my game.
As you can see this is the third uh ground.
So basically this uh, sorry, uh, this is our first ground.
And the second ground, round, which is calling in the start function and we do not start function
get call in the start of the game.
So that's why that ground, the next ground or the second ground just gets spawn from a from here,
which we defined the position.
And the third ground we can see it just gets spawn from this next position.
And we can just click on this play button in the top in order to get out of play mode.
And I'm going to click on this play button to play our game in order to have a look more of it.
So let's click on this play button in order to get out of play mode.
And let's click on this play button one more time in the top in order to see, uh, in order to see
that, uh, basically it's gonna spawn the different ground by now.
It should.
So I'm going to click on this pause button in the top to pause my game.
And we can see now different ground just gets spawn.
So the next ground or the second ground just gets spawn from here which we define it.
So if I select my ground spawner script in hierarchy we can see which is spawned at the next spawn post.
So basically this is.
And the third round just gets spawned from this next position as you can see.
So basically this is the thing I hope you get the idea.
And let's have a look on this.
And I'm going to make the player speed a little bit fast in order to see the ground just getting spawned
or spawn it or not.
So let's, uh, click on this play button.
Uh, sorry, I'm going to click on this pause button in the top to unpause my game.
But before we do, I'm gonna make the player speed a little bit high.
So I'm going to select my player GameObject in the hierarchy.
And let's go to Player Script in Inspector.
And I'm going to make the speed, uh, something like uh 5 or 7 we can to.
And now let's click on this plus button.
And we're gonna able to see once we trigger with this you will see the next spawn over here.
So as you can see as soon as we trigger it with this box collider.
So let's click on this pause button to pause my game.
And if I select this crown.
So in our case this.
So as soon as we get inside we can see uh the next round just gets spawned from this next position as
you can see.
So let's suppose if we trigger with this, uh, box Collider 2D, you will see the next crown just gonna
spawn from here.
Something over here.
So we're going to take a look.
But before we do, uh, let's select this crown underscore three.
So once we're going to trigger with this you will see the next crown.
Just spawn from this next position.
Because every time we just changing the next spawn pose with our next crown prefab.
Uh next spawn uh next position.
So let me show you you will see that.
So I'm going to make our my as player speed a little bit low.
So I'm going to select my player game object in the hierarchy.
And I'm going to make the speed of player something like four.
And let's click on this pause button to unpause our game.
As soon as we're gonna trigger with that box, you will see that.
So as you can see, as soon as we trigger with this, we can see the next round just gets spawn and
it's gonna spawn for ever once we trigger.
As you can see, basically, this is the cool thing and let's get out of play mode.
I hope you get the idea that how you can do it.
And I'm gonna press down Ctrl s in order to save my project.
But before we do, let's make this ground spawn game object a prefab prefab.
So I'm going to have the copy.
Firstly, I'm going to select my ground spawner GameObject in the hierarchy, and let's press down F
in order to focus on that game object.
And let's move over to project tab, then assets and then prefabs folder.
And I'm going to select my Ground spawner GameObject in the hierarchy.
And let's drag it over to that prefabs folder in order to make it prefab.
So I'm going to have the copy.
And now we're going to press down Ctrl S in order to save our sorry.
In order to save our project.