unity-scripting

Installation
SKILL.md

Unity C# Scripting

Script Fundamentals

C# scripts (.cs files) are stored in the Assets folder. Scripts gain Unity functionality by inheriting from built-in types:

  • UnityEngine.Object -- Makes custom types assignable to Inspector fields
  • MonoBehaviour -- Attaches to GameObjects as components to control behavior in a scene
  • ScriptableObject -- Standalone data assets not attached to GameObjects

Scripts operate in two contexts:

  • Runtime scripts -- Execute in the Player build (use UnityEngine namespace)
  • Editor scripts -- Run only in the Editor (use UnityEditor namespace, place in Editor folders)

MonoBehaviour Lifecycle

MonoBehaviours always exist as a Component of a GameObject. The lifecycle event functions execute in a strict order. You cannot rely on the order in which the same event function is invoked for different GameObjects unless configured via Script Execution Order settings.

Execution Order (ASCII Diagram)

Related skills
Installs
16
GitHub Stars
14
First Seen
Mar 19, 2026