In Unity, scripts are written in C#, which is an object-oriented programming language.
In this tutorial, I will be showing how to create a C# script in Unity.
Create a script
- Right-click in the Project view -> Create -> C# Script
- Type any name and press Enter
The new script is created and can be attached to a Game Object, however since it's empty, it needs to be edited in order to add some functionality to it.
- Double-click to open the script
Default C# script already includes some parts:
- 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 game (there is another built-in function with similar functionality, called void Awake(), that is called before Start()).
- void Update() is another built-in function that is called each frame and is used for implementing continuous logic such as key-press, player movement, etc. (similar functions are LateUpdate() and FixedUpdate()).