We'll come back.
In this video, we will have a look at our new behavior script, which is the script that we have created
in the last video.
If you want to create a script yourself, you can do right click in your assets, create and click on
C-sharp script.
Another way to create a script is, for example, click on one of your game objects, for example,
the cube.
Then add a component.
Here on the right hand side, you can create a new script.
You can add a name here, new behavior script, and you can choose the language here.
So if you want to program in JavaScript, you could choose that here as well, and then simply create
and add and it will be added to your assets folder.
But I'm not going to do it this way because I have the script already.
So let's open up that script.
And usually if we double click it, it opens in our IDE, for example, in Visual Studio, and it could
also open up in mono develop if you if you use that or in any other IDE that supports C-sharp and Unity.
I highly recommend, however, to use Visual Studio.
All right.
So let's have a look at this new behavior script because we have already 16 lines of code, even though
we haven't written any single line or even any single symbol yet.
So what we have here is using we have three lines of using something, which means that we are using
a namespace.
You can consider those or you can imagine those being modules which add a bunch of functionality to
your script and those allow us to use this functionality.
So we're not using it currently because we have not used any of those too.
As you can see, they are grayed out, but we are using some of the unity engine functionality and we
do that within mono behavior because mono behavior is one of the classes that is within Unity Engine.
If you want to know more about mono behavior, what you can do is hold your command key and press on
mono behavior.
What that does, it opens up the assembly browser and then you will find here the information about
this class that has plenty of code that might be a bit too much for you as a beginner, but if you know
programming already, you might make sense out of it.
In the end, there are plenty of methods which we can use in our games or in our scripts in general.
All right.
So what do we have here?
We have a public class called New Behavior Script Colon, mono behavior.
This colon means that we are inheriting from mono behavior, which means that we can use the functionality
of mono behavior.
And we have the behavior of this class, and this class is mono behavior.
So within those things there is somewhere the start and the update method which are already there.
So we don't need to write exactly when the start method or the update method is called.
It's all done within our unity engine namespace.
So all of that is written there.
We don't need to write that code.
So now that allows us to make it super simple.
We can simply say, All right, we want to do something when the start method is called, then we want
to do something whenever the update method is called.
So those two methods, they are within a class and that's generally how classes are built.
They have variables and they have methods and we can create our own variables.
We will do that in the next video and we can create our own methods, or we could use methods that are
internally created already.
So we don't need to build them ourselves, we just need to call them or we can override them to make
our own of it.
But all of that is going to be covered as soon as we get there.
What is important for now is that, you know, that we automatically create a class and that has automatically
two methods which we could choose to delete or we can choose to use them.
So let's have a quick look what those to do.
For example, let's write, we have print statement onto our console.
So for example, we say start method was called
and in the update method we do the same thing.
Print update method was called.
So now we will know within unity within our console, we will get information about when what was called.
So which point was the start method called and when was the update method called?
What do those two methods do?
The START method is called at the beginning, when the game object that contains our new behavior script
is created and the update method is then called with every single frame.
So as soon as the object is there, the update method will be called all the time, once per frame,
which means if we have, for example, 60 frames per second, then this update method will be called
60 times.
Within that second.
All right.
Let's check that out before we go any further.
So let's save that script.
And now let's go to Unity.
If we run the code now like that, there will be nothing printed onto our console.
As you can see, maybe it's best if I don't go to maximize on play here.
So let's run that again.
Go to our console and you can see nothing happens.
So no information was printed if we now, for example, add that new behavior script to our cube.
Then we can see it here on the right hand side.
So I clicked on the cube and in the inspector on the right hand side, I can find my new behavior script.
And for example, I could remove it and I can alternatively drag it in like that.
So I added it like with a drag.
Remove that component again.
And the third way is to add a component, then go to scripts and then add this new behavior script.
So now our cube has the script.
If we run the code now, we will see a different story here.
So let's go to our console and you can see start method was called has a one here at the at the end
which means it is called once and update method was called has already been called 500 times.
So that means it has been called with every single frame.
So as you can see, well, maybe you can roughly estimate how many frames per second I have should be
like 30 or 50 or something like that.
So it's called very many times and that's what you have to consider.
So whenever you write your code within the update method should not be any heavy code that will load
many, many information or will execute a lot of different functionality because otherwise that could
reduce the performance of your game.
So keep the update method lightweight and use the START method for initialization.
What that means will make make a lot more sense when we go on with the course.
So no worries if you don't understand what initialization means.
No worries if you don't understand what this print statement means.
Well, in the end, it's really just for programming services.
It's really just for us so that we know that, so that we can see within unity what's going on.
So that's what we've just written for ourselves.
So we can, for example, check what value our player has.
So for example, how many points he has or whether he tapped a button or those kind of things.
That's what we can use this for.
Two more things.
What we haven't covered yet is the two forward slashes, double forward slash means this line is a comment.
So everything that follows this double slash will not be considered within the game.
It will not be executed, it will not do anything.
It's really just for us in code so that we can read our code in a better way.
So now we understand.
Okay, the start method is for initialization.
The update method is called once per frame.
Alright, very helpful.
All right.
So then the next thing is we have curly brackets as the start and the end of something.
So this is the start of our class and this is the end of our class.
The same thing with the start method.
This is the start of the method curly bracket open and this is the end of our method curly bracket closes.
And of course after every single statement, for example, this print statement, we need to have our
semi-colon.
All right, great.
So these are some very basic things I just wanted to show you.
And in the next video, we are going to have a look at variables.
And if you haven't understood everything you saw here, no worries, you'll get a better feeling for
it later on.