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.
Suggested Articles
Introduction to Unity Editor UI
Creating 2D Animations in Unity
How to Assign a Camera to a Script in Unity
How to Create a New Project in Unity
How to Install Unity and Create a New Project
How to Create Terrain in Unity
How to Change Skybox in Unity