How to Create a New C# Script in Unity

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.

To create a C# script in Unity follow the steps below:

How to Create a New C# Script

  • Right-click on the Project view -> 'Create' -> 'C# Script'

Unity Create C# Script

  • Type any name and press Enter

Some Script

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

Script Structure

Unity c# default script structure

Unity's default script structure is as follows:

  1. Namespace references (groups of classes that can be used in the script).
  2. Class name that inherits from MonoBehaviour (Unity's base class).
  3. Start() is a built-in function that is called at the start of the script initialization.
  4. Update() is a built-in function that is called every frame and is used for implementing continuous logic such as key-press, player movement, etc.
Links
Unity 6