In simple terms you can think of Unity’s architecture as consisting of two layers: a lower-level native (C/C++) layer of core functionality which you can’t interact with directly, and a higher-level managed (C#) layer wrapper which you can interact with through scriptsA piece of code that allows you to create your own Components, trigger game events, modify Component properties over time and respond to user input in any way you like. More info
See in Glossary.
This section introduces you to key concepts of scripting in Unity, including how to create and structure your scripts, plus core scripting features you can use to control the runtime behavior of your application.
Topic | Description |
---|---|
Create and use scripts | Create and use scripts to add functionality to your application. |
Variables and the Inspector | Add variables in scripts that inherit from the MonoBehavior class and edit them through the Editor’s InspectorA Unity window that displays information about the currently selected GameObject, asset or project settings, allowing you to inspect and edit the values. More info See in Glossary window. |
Instantiating Prefabs at runtime | Instantiate PrefabsAn asset type that allows you to store a GameObject complete with components and properties. The prefab acts as a template from which you can create new object instances in the scene. More info See in Glossary at runtime as a convenient alternative to instantiating complex 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. |
Event Functions | Define event functions in your scripts that Unity calls in response to events in the running application. |
Order of execution for event functions | Unity calls certain event functions in a defined order during the lifecycle of your script objects. |
Coroutines | Use coroutines to spread tasks across several frames. |
Namespaces | Use namespaces to logically organize your scripts and prevent class name conflicts. |
Attributes | Use Attributes on classes, properties and methods in your scripts to add metadata to your program which determines special behavior at run time. |
UnityEvents | Persist user-driven callbacks between Edit mode and Play mode with the UnityEvent class. |
Null Reference Exceptions | Learn how to interpret, handle, and avoid null reference exceptions in your code. |
Asynchronous programming | Use Unity’s support for the .NET asynchronous programming model in your scripts. |