A Script is a document that contains programming instructions in a certain language, which is the one understood by the tool we are using to develop any application that requires programming.
MOST SEARCHED VIDEOS FROM MY CHANNEL
Some examples of the use of Scripts
For example, a Script may contain a list of instructions for an Arduino to perform a function. It can also contain a set of rules that define the style of a web page. A simple game could be coded in a Script.
C# language scripts used in the Unity engine
In our case we are going to use Scripts within the Unity engine, these Scripts will be written in C# language and most of the time we will make these Scripts fulfill a certain function within Unity, using the objects and components of the hierarchy and performing logical and mathematical operations necessary for the development of the mechanics of the game.
What's inside a Script in Unity
When creating a new Script in Unity, inside it will be defined by default a PROGRAMMING CLASS with the same name that we gave to the file, this class will extend from the MonoBehaviour class defined in the Unity Engine, it will also have two methods (or functions) defined, the Start function and the Update function.
How Scripts run in Unity
In order for the code we define inside a Script to be executed, the Script must be assigned to at least one GameObject in the hierarchy (the Script has to extend from MonoBehaviour in order to be added to a GameObject) and also that GameObject has to be active in Hierarchy.
This is enough for Unity to add it to its execution cycle, when entering the game mode, Unity will execute at certain times some of the functions that are defined within the Script, for example the Start, Update and FixedUpdate functions, and it will do it automatically.
What scripts are used for in Unity
Unity is a software that is known as a graphics engine, this software facilitates many technical issues when creating graphics applications, because if we did not have it, we should manually program functions that tell the graphics cards how to render what we want to appear on screen, using libraries such as DirectX or OpenGL. Unity also provides us with a physics engine that allows us to detect collisions and represent interactions between objects as if they were rigid bodies, with the most common physical properties they have. Audio processing is also an important feature of the engines.
Unity offers us a series of very useful tools and that otherwise would require a lot of technical knowledge, but to be able to handle these tools two things are needed, one is to know the Unity engine, that is to say to become familiar with these tools and to understand what function they fulfill. And the second thing we need is to know how to program to make use of these tools, and we will do that through programming scripts.