Unity uses C# for scripting, which is an object-oriented programming language.
Scripts are blocks of code that are written in a language that Unity can understand (C#) and are used to program game logic and every aspect related to technical implementation.
In this tutorial, I will be showing how to create a C# script in Unity.
Create a script
To create a Script in Unity:
- Right-click on the Project view -> Create -> C# Script
- Type any name and press Enter
The new script is created and can be attached to a GameObject, however since it's empty, it needs to be edited in order to add some functionality to it.
- Double-click to open the script
Unity's default script structure is as follows:
- Namespace references (groups of classes that can be used in the script).
- Class name that inherits from MonoBehaviour (Unity's base class).
- void Start() is a built-in function that is called at the start of the script initialization.
- void Update() is a built-in function that is called each frame and is used for implementing continuous logic such as key-press, player movement, etc.