Version: Unity 6 Beta (6000.0)
Language : English
Unity scripting features
Variables and the Inspector

Create scripts

Eventually you’ll want to create different types of scripts to customize and extend the capabilities of your applicaton. With scripts that derive from Unity’s built-in MonoBehaviour class you can create your own custom Components to control the behavior of GameObjectsThe fundamental object in Unity scenes, which can represent characters, props, scenery, cameras, waypoints, and more. A GameObject’s functionality is defined by the Components attached to it. More info
See in Glossary
. With scripts that derive from ScriptableObject you can store large amounts of data efficiently in your application. Alternatively, you can start with an empty C# script to develop your own non-Unity classes.

Unlike most other assets, scripts are usually created within Unity directly. To create a new script:

  • From the main menu: go to Assets > Create > Scripting and select the type of script you want to create.

Or:

  • From the Create menu (plus sign) in the Project window toolbar: go to Scripting and select the type of script you want to create.

This creates a new script in whichever folder you have selected in the Project panel. It also selects the script’s file name for editing, prompting you to change the name.

Naming considerations

The file name you enter on creation of a script will also be used for the name of the class defined inside it. It’s good practice for a script’s file name to match the name of the class defined inside it.

For scripts derived from the built-in Unity types MonoBehaviour and ScriptableObject, Unity can still resolve a class type defined in your script even if the file name doesn’t match, but there are some limitations:

  • If multiple classes are defined in your script, Unity selects the class with the same name as the file.
  • If you use the C# partial keyword to define a single MonoBehaviour-derived class across multiple files, only the file with the same name as the partial class can be used as a Component.

Note: In all cases where a class name can’t be unambiguously matched to a particular file, Unity displays a warning.

Type-specific guidance

For information on using scripts derived from Unity’s common built-in classes, refer to their dedicated reference pages:


  • 2018–03–19  Page amended

  • MonoDevelop replaced by Visual Studio from 2018.1

Unity scripting features
Variables and the Inspector
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961