What are Scripts and what are they for? — Example of use in Unity


A Script is a doc­u­ment that con­tains pro­gram­ming instruc­tions in a cer­tain lan­guage, which is the one under­stood by the tool we are using to devel­op any appli­ca­tion that requires programming.


Some examples of the use of Scripts

For exam­ple, a Script may con­tain a list of instruc­tions for an Arduino to per­form a func­tion. It can also con­tain a set of rules that define the style of a web page. A sim­ple game could be cod­ed in a Script.

C# language scripts used in the Unity engine

In our case we are going to use Scripts with­in the Uni­ty engine, these Scripts will be writ­ten in C# lan­guage and most of the time we will make these Scripts ful­fill a cer­tain func­tion with­in Uni­ty, using the objects and com­po­nents of the hier­ar­chy and per­form­ing log­i­cal and math­e­mat­i­cal oper­a­tions nec­es­sary for the devel­op­ment of the mechan­ics of the game.

What's inside a Script in Unity

When cre­at­ing a new Script in Uni­ty, 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 MonoBe­hav­iour class defined in the Uni­ty Engine, it will also have two meth­ods (or func­tions) defined, the Start func­tion and the Update function.

How Scripts run in Unity

In order for the code we define inside a Script to be exe­cut­ed, the Script must be assigned to at least one GameOb­ject in the hier­ar­chy (the Script has to extend from MonoBe­hav­iour in order to be added to a GameOb­ject) and also that GameOb­ject has to be active in Hierarchy.

This is enough for Uni­ty to add it to its exe­cu­tion cycle, when enter­ing the game mode, Uni­ty will exe­cute at cer­tain times some of the func­tions that are defined with­in the Script, for exam­ple the Start, Update and FixedUp­date func­tions, and it will do it automatically.

What scripts are used for in Unity

Uni­ty is a soft­ware that is known as a graph­ics engine, this soft­ware facil­i­tates many tech­ni­cal issues when cre­at­ing graph­ics appli­ca­tions, because if we did not have it, we should man­u­al­ly pro­gram func­tions that tell the graph­ics cards how to ren­der what we want to appear on screen, using libraries such as Direc­tX or OpenGL. Uni­ty also pro­vides us with a physics engine that allows us to detect col­li­sions and rep­re­sent inter­ac­tions between objects as if they were rigid bod­ies, with the most com­mon phys­i­cal prop­er­ties they have. Audio pro­cess­ing is also an impor­tant fea­ture of the engines.

Uni­ty offers us a series of very use­ful tools and that oth­er­wise would require a lot of tech­ni­cal knowl­edge, but to be able to han­dle these tools two things are need­ed, one is to know the Uni­ty engine, that is to say to become famil­iar with these tools and to under­stand what func­tion they ful­fill. And the sec­ond thing we need is to know how to pro­gram to make use of these tools, and we will do that through pro­gram­ming scripts.

Scroll to Top
Secured By miniOrange