Which you serialized.
Phil.
So I'm going to select my player game object in the hierarchy and let's open up the player script.
And what we're going to do, we're going to go over to the top of our class.
And over here, as you can see we're setting public float jump height and equal to seven.
Instead of making this public we can simply make this one private.
But if we make this one private, we're not going to able to see underneath our player skip in inspector.
So how we can able to see even we set it to private because basically we don't need this parameter through
another script or another class.
So we can make this one private.
And so we're going to make this one private.
So let's make this one private.
But if we set it to private we're not going to able to see underneath our player skip.
So we cannot able to adjust it underneath our player skip.
But let's suppose we still want to see this parameter.
So what we basically have to do.
We need to make these square brackets.
And over there, over here we basically need to pass this serialized field.
Now we're going to able to see this parameter.
Even it's set it to private.
But the problem is that you're not going to able to access this parameter through another class or another
script, something like if I just move over to enemy, enemy.
And let's suppose in the start function over here in awake function, I'm going to use this find any
object of type.
And over here we need to make this first a arrows.
And then uh here we need to pass the script name which script we're looking for.
So let's suppose we're looking for our player.
And then we need to make this first bracket.
And then we can just use this dot in order to access any parameter we like.
So if I just try to access them, as you can see we're not able to see this parameter even.
It's even we are able to gonna able to see this jump height parameter underneath our player skip.
Because with this we made this parameter private and we just made it a serialized field.
So we're going to able to see underneath our player skip.
But the problem is that we're not going to able to access this parameter through another class or another
skip as you can see.
So if I just move over to player Skip and then try to access the jump height, as you can see, we're
not able to see that because we set that parameter to private.
But we set also serialized serialized field.
We are gonna able to see underneath our player skip.
So I'm going to remove this.
Let's go to player Skip.
And I'm going to press down control S to save our skip.
And I'm going to make this a acceleration as well.
So it doesn't need to be public.
Instead we're going to make this one private.
But we're going to mark it as a serialized field.
So we're going to able to see underneath our player skip.
So this will be we're going to pass serialized field.
And let's do the same thing with this speed parameter.
So I'm going to make this as square brackets.
Serialize fill.
And we're going to set it to private.
So even we're setting this parameter private we're still going to be able to see this parameter underneath
our player scape.
But we're not going to be able to access this parameter through through another class or another script.
And I'm going to do the same thing with this animator rigidbody.
So making this our, uh, our basically, uh, code just gets clean more clean.
So I'm going to pass serialized field and let's do the same thing with this serialized field.
And this will be private.
And let's do with this one as well.
So I'm going to mark as a serialized field serialized field.
And let's pass private here.
And I guess this is fine.
And now we can simply go over here and we make this as well.
But I'm not gonna do it with this.
You can make this.
Uh, as well.
Private and then serialize field.
So you're gonna be able to see.
Underneath your player's game.
So I'm gonna press down Ctrl s to save script and let's move over to unity.
So even we set it to private, we still.
Gonna be able to see underneath our player Skip.
So we get a problem if I move to console tab.
Uh, so player dot speed is inaccessible due to protection level.
Basically we set this speed parameter to, uh, to private, as you can see.
But we still able to see this parameter underneath our player skip.
But the problem is that we, uh, we just accessing this speed through another class.
So if I move over to my ground spawner skip and then basically where we're using.
So we need to find that.
So let's do why are we doing.
Ground spawner program manager.
Follow script.
And so if I move to unity and we can see the error in acid script and follow script.
So we have done in this follow.
So as you can see we accessing the speed parameter over here in this follow script.
But we do know that we just made that this speed parameter underneath in our player skip a private parameter.
And we just marked as a serialized file.
But over here we trying to access.
So what we basically have to do we need to make that speed parameter public instead of marking as a
serialized field because we accessing the speed parameter that as you can see through another class
or another script.
So that's why we need to merge that parameter as a public.
So let's go to player script.
And we're going to mark this as a public.
So we're going to mark this as a public.
And I'm going to move this one.
This parameter in the down direction by holding down alt key and using up or down arrow key.
So you can move that any line of code anywhere.
Now I'm going to press down Ctrl S to save our script.
And let's move to unity by now.
So just wait for to compile.
And once it's done we will be able to see that.
So we just accessing that speed parameter.
So that's why we need to make it public.
Because we just accessing through another C sharp script or class.
Uh but uh basically that is the thing.
And we can see the speed as well underneath our player script.
And if we just click on this play button, it should be fine.
Even if we set this parameter to private, we still able to see underneath our player script because
we just marked as a serialized speed.
So that is the reason.
So just wait.
And this is fine.
So I'm going to get out of play mode.
And we also need to do some coding stuff to just make our coding a little bit more clean.
So just wait for a little moment.
I need to plug my charger to my laptop.
This is fine.
So what we're going to do.
So let's suppose you just want to type header over here.
Or you just want to give it a title underneath your player.
Skip somewhere over here before you just create this parameter so you can give it a title as well.
To do that open up the script.
And let's suppose, uh, I'm gonna move over to basically, I'm gonna adjust all of the speed parameter
about movement of our player game object at once.
So this is our health distance ground speed.
So over here I'm going to do that.
So before I make these parameters.
So I'm going to make it separate.
So if you just want to give it a title then you basically have to type these square brackets and then
type this header and then make first bracket.
And in you have to pass the string.
So in quotation you can say so in quotation I'm going to say something like player movement.
Player movement.
Basically I'm just giving the title uh title.
Uh why I just name it player Movement.
Basically this over here, as you can see, this is our acceleration.
This is jump and the speed of our player game object.
So that's why I just gave it a title player model.
Because this parameter is related to our, uh, speed or player movement.
So that's why I just gave it a title.
Uh, as you can see, which is player movement.
You can just name it, uh, same or you can just go with different name as well, or the title you would
like to go with.
And this over here, This section, we can simply call it like checking distance with our ground.
So we can give it a title as well.
So I'm going to type header.
And I'm gonna say something like checking distance I guess it's not checking distance.
Or basically this is our attack system attack.
Basically this parameter A is about attack.
This is our rail length and this is enemy layer and then line renderer.
So basically this is our attack system.
And I'm going to move this shoot point in this over here.
So it's going to be fine.
Uh basically I just want to move all of the same name parameter or same section parameter at once.
So I'm going to move this one down by holding down alt arrow key alt and arrow key.
And I'm going to give it a title in this section, this section to something like attack or player attack.
So let's give it a title player attack.
Or we can simply code shoot as well.
Shoot player or I'm going to leave it to shoot and let's press down Ctrl S in order to save our skip.
And let's move over to unity.
And if you just want to make spaces between these, uh, parameters, you can do that as well.
So just wait.
And, uh, as soon as the script gets compiled, we can see now underneath our player Skip, we have
a player movement title as well as we have the title or the header as you can see.
So this makes lot clean our code.
And let's suppose you just want to make spaces between this parameter.
You can do that as well by going over to script.
And then let's suppose I want to make a spaces between this animator and RB parameter.
So what I can do, I can just uh, make this square bracket and you just have to type this space space
and then make first bracket.
And this first bracket, you can just put the how much space a space that you want so you can put it
to ten.
You can put it 20.
So let's suppose I'm going to put it 30.
Or you can just go with smaller number and that's going to be fine.
But for checking purposes I'm gonna move I'm gonna give a bigger number.
And now if I just press down Ctrl s and then move to unity, you will see that.
So just wait for to compile.
And once it's done, we're gonna able to see that we're gonna have spaces between RB and animator parameter
underneath our player skip.
So just give it a moment to compile our script.
And as soon as we compile we can see now we have spaces between this RB and animator parameter.
So much so you can just give or you can just give a small number.
So the spaces between these parameter is just gonna be small for testing purposes I just give it this.
So that's why.
And let's suppose you still, uh you just want to hide this parameter, this animator or this RB underneath
your player.
Skip.
So what you have to do, let's suppose I just want to hide this animator parameter underneath my player
skip.
So what I can do I can simply move over to Skip.
And I'm going to remove this space.
And let's suppose I just want to hide this animator parameter underneath my player skip even.
It's set it to public.
So what we basically have to do before you make the parameter, make this square brackets and type this
hide in inspector.
And now if you just press down Ctrl S and then move over to unity, you will see that this animator
parameter will be hide right away.
We're not going to able to see underneath our player script.
So you will see that.
So just wait for to compile.
And as soon as it's compiled we can see that we don't have the animator parameter underneath our player
skip as you can see.
So we just added.
So if you just want to hide any parameter that you want to hide it, then you can just use that as use
that format in order to hide the parameter that you really want to hide it.
So I'm going to open up my player script and uh, we don't need this parameter.
Or we can simply just remove this.
And let's suppose I don't want to set this parameter public, this animator, but still I want to grab
the reference.
So what we can simply do, we can open up our player script.
And I just want to make this animator, uh, parameter private.
So I'm going to make this one private.
Private.
So if we make this one private we're not going to able to see this animator parameter underneath our
player script.
But let's suppose we still need to get the reference.
Basically we need to select this animator and drag it right there into that slot.
So we're going to have the reference.
But uh, in this uh format we're going to use another uh another format or another.
You can simply say another code in order to get the reference.
So what we basically have to do, we need to move over to this start function or awake function.
So this start function get call in the start of the game.
So in the start of the game I just want to grab the reference.
So if we just made it private so we're not going to have we're not going to able to see that animator
parameter underneath our player skip.
So so player skip.
But we still want to grab the reference of this animator component.
So we need to move over to this start function.
So this start function get call in this start of the game.
So in the start of the game what I'm going to do I'm going to use this this dot get component.
And the component you're looking for you need to make inside this arrow.
So the component I'm looking for is an animator.
So we're going to type this animator and then make this first bracket and then close that off with semicolon.
So basically this just over here is just referencing itself.
So the player script is attached to this player game object.
So this basically just it's referencing itself.
And then we're just getting this animator component or basically we just getting this or taking this
animator component, as you can see over here.
And now what I'm gonna do after taking that animator component, I'm going to store the animator component
into this animator variable.
As you can see, we created over here and we set it to private.
We're not going to able to see underneath our player Skip.
So we're gonna firstly take the animator component.
Now what we're gonna do we're gonna store this animator component into this animator parameter.
So let's do that.
So we're gonna set animator equal to this.
Now we can see we have the reference basically, which is taking this animator component of this player
game object.
And then we're storing this animator component into this animator parameter.
As you can see over here now we have the reference.
Basically we have this animator component.
And now we can just simply switch the animation as we have done already.
So make sure you just press down control S in order to save your skip.
And now let's move over to unity.
So making this by this our code just gets a lot more clean.
So basically that is the purpose using of that.
And we're gonna do the same thing with this RB as well.
So now if I just click on this play button we should not get any error because we have the reference,
this animator component in the start of the game of our player game object.
Basically, in the start of the game, we're just grabbing this animator component, and then we're
storing this animator component into our animator slot.
Sorry animator parameter as you seen.
And I'm going to do the same thing with this RB or this rigidbody as well.
I don't want to see this RB field underneath my player Skip.
So our player Skip just gonna be clean in the inspector.
So that is the reason of doing that and making our code a lot more clean.
So let's go to Skip.
And we're going to make this a rigid body as well.
A private.
So I'm going to use this private.
So we do know once we set it to private sorry I'm going to remove this private.
So we're not going to able to see our this RB underneath our player skip.
Why.
Because we made it private.
But we do know that we still need to create the reference of this rigid body.
Then this player game object just going to able to jump.
So we're going to grab the reference of this rigid body 2D of this player game object in this start
of the game.
So let's go to script and let's move over to this start function.
So in this start of the game firstly I'm going to grab the reference.
So we're going to use this this dot get component.
And the component we're looking for is a rigid body 2D.
So I'm going to type this rigid body 2D and then make first bucket.
Then close that up with semicolon.
So basically we're just taking this rigid body 2D in the start of the game.
And now after taking this I'm going to store this rigid body 2D into this RB field as we created over
here.
So let's set.
So I'm going to say RB equal to this.
So firstly we basically are getting the rigid body compound 2D component basically this one.
And then we just storing this rigid body 2D parameter in this rb rb parameter that we created which
is short form of rigid body 2D.
So basically we're just getting the reference or we're just taking the rigid body 2D reference in the
start of the game as you can see.
And then we just storing into this RB now we have the reference.
So I'm going to press Ctrl S to save my script.
And let's move to unity.
So you can do our approach.
Same thing with another class or another script as well.
So to just uh, making your basically to make your uh, code clean.
So it's gonna be fine.
And now if I just click on this play button in the top, you will see and it's gonna be fine.
We should not get any error because we have the rigid body reference, as well as we have the animator
reference, and we still we see that we not don't have any error in the console tab as soon as the game
started means we have perfectly grabbed the reference and we don't have any error.
And I'm going to get out of play mode.
So you can do with same thing with another like this in this anime two script as well to just keep your
as enemy, to skip a little more clean.
As you can see, it seems totally messy, so we can just approach the same thing as we have done in
this player game object.
So you can just do that.
I hope you get the idea that how you can make your, uh, code clean.
So it's gonna be fine and someone can easily read the code as well.
So I'm going to press down Ctrl s to save my project.
But before we do I'm going to select my player game Object Overrides.
And then I'm going to click on this Apply all.
And now let's press down Ctrl S to save our project.
And that's it's fine.
That's fine.