Let's go on with the scene we used in the previous unit as an example. We had different folders, and now we've added a new one called 'Scripts'. In this folder I have already created some scripts we will now see, which are linked to the root, are these two files, which we can also see in the structure inside Unity. If we click in any of them, let's begin with the rotation, here in the inspector we get a small visor on the code inside this script. But to create and edit them we need to open them with a specific program in a development environment. If we click Open it will open, in my case, MonoDevelop, and here I get the script code. Well, we aren't going to give a lot of information on how to understand and program all the scripts, as it belongs to the courses dedicated to game engine and gameplay. But first let's understand at a conceptual level what do scripts do, right? So here there's basically one instruction generated in the Event update subroutine, with which we calculate each frame, and what it does is modifying Transform Rotate, giving it a new vector that has these coordinates, with a time factor so that they can be done regardlessly of the frame. What is Transform Rotate? Transform rotate is a parameter we know our object has, which we assign it, we have already seen that in our cube we have a transform, and in rotate we can modify its rotation. When the different scripts are generated it is very important to work along with the documentation that we are given, in this case, by Unity, and this can be easily done from Unity's web. If we go to Unity documentation, either in Google or in Unity's web, we have access to a lot of documentation on how to create the different scripts and many more things, apart from the scripts on the program. There we can find a lot of information and, in example, about each different command, we have examples on how to apply them, which effects they have, how to write them, variations and how are they related with other scripting elements. This way, creating scripts becomes a bit easier. Well, as we were saying, this script basically adds a rotation factor to one of the axis, so we are going to apply this script to an object, in this case we have two objects in the scenario, one is the floor and the other one is the cube. Nothing else. So, what are we going to do? We select the cube and we go to the inspector, and as we said, scripts are components, so we will add a new component, here in the list of the possible components we can add, we go to scripts and in the scripts list we select the one we want. Unity reads all the scripts in our project and offers us these two. If we had rooted more there would be more. Well, we want the rotation one. When we click here this component has been added and we have a small checkbox which tells us whether it is active or inactive, we will leave it active and well, here we can see it has its name assigned and it's working. Then, how can we see if this script is working? We must execute the game, that is, setting Unity in Play mode. We press here and, as you can see, Unity gets into execution mode, if I zoom in, the cube is moving using the instructions we've given to the script. This is the play mode, I can pause and unpause it whenever I want and to stop it I must deactivate this execution mode. Now I can edit again. It is important knowing that, in Unity, while you are in Play mode, you can edit some parameters, although right now we don't have any specific one here, but we could do things, even moving certain elements and modifying other ones. Well, while we are in Execute mode these changes we make aren't saved, when we go back to edition mode, they go back to their previous state. Any change we want to make needs to be, not in execution mode but in edition mode, which is the default one. Well, this is a basic scripting function, let's see another example, in this case, with the second script, the Ball one. To do so we will create a new game object which will be a sphere. It will be submerged here, we will move it, so we can see how to move objects. Well, now we will also give a look on how the script works before using it, we will also open it. This one is a bit more tricky, although it isn't complicated. Basically, we will apply a force to the object assigned to this script, which in this case will be the ball, we will apply this ball a force so that when we do it the ball spins and we can move it. To do so we must take many things into account: the first one is that if we want to apply a force, there are many ways to do it, but one of them is working with the physics engine Unity has. If we want to work with the physics engine Unity has, which allows us to ease and accelerate the forces calculations, movements and speeds we want to do, we must take into account many requirements. The first one is that objects to which we want to apply the physics engine effects must have rigid body, they are physics components. We will apply it to our sphere, and we will add it a physics component, which will be RigidBody. When applying this component, we are giving mass to the object and we are making it respond to the physics calculation of the rest of the game elements that also have RigidBody and are inside the physics calculations. Let's go back to the script. The first we do is calling this component, we create a variable, we give it RB as a name and we call the RigidBody component. Scripts are attached to an object, but we must reference if we want to access to another component in the same object. So we reference and say "I'll call the component of this object that is RigidBody. Then we have another variable which is speed, the public variable that will allow us to modify the speed we want the ball to move in the editor in this case. So, the specific functions in the start function, what we do is giving our RigidBody variable, giving it the concrete component, calling the same RigidBody component the object has to give content to this variable. And then in the fixed update event's function each frame calculates, it is ready for events related to physics calculations, and we do the following: we create two movement variables, horizontal and vertical, and in each of these variables what we do is capturing the Input.GetAxis. Input.GetAxis is simply the information given by the control device, which can be the keyboard, a commandment, etc. The control device has many sources, which can be the horizontal and vertical axis, another one can be the shoot key, the jump key, etc. What we do here is taking the horizontal and the vertical axis' movement and placing them in a variable. Next we will create a vector which will be the one that will determine which will be the force's direction, and this vector will have the information we have captured from the control. As you can see we are capturing the horizontal and vertical information, as we don't want a movement towards the superior axis, upward. And finally we make the calculation or the function that will determine the movement, which is applying it to our physics component, RigidBody, which is the variable to which we have previously given a value, so we apply a force and we give it a direction and a speed multiplier, which is the variable we've previously created. So, to sum up, we are applying a force with a direction and an intensity. When we save it and apply it, we see it this way. This is our sphere and as we know, as we have done before, we give it scripts and we apply it ball. It automatically adds this component and here we can see we have a configuration option that is called speed, and this is because the speed variable has been set as public. This allows us to easily adjust this kind of parameters. Now it's 0, let's see what happens if we execute. Well, the sphere hits the floor, doesn't move, the cube has another trajectory because it has another script, the one we did before. I'm gonna try to move it with the keyboard, and indeed it doesn't move. This happens because we haven't given a value to it, and it is multiplying its movement by 0. We must give it an intensity so that there is a movement. OK. Now it is moving, it falls down the edge. This way we are applying a force, we are controlling the applied force with the keyboard, we are moving an object with the controller. Obviously now it is very hard to control because the camera is locked, and obviously the axis. It is hard to concrete the direction to which you want to move the object. The good thing about working this way, is that you can create the different parameters and control their intensity, their precision, their speed, etc. Right now there's only one intensity or speed parameter, but we can add more parameters. This is a basic example on how to create small scripts which add behaviors to different elements on the scene. Next we will see a bit more complex example on how we can create more elaborated interactions to create a small video game.