AI Agent Hub
Back to skills
💻

Unity C# Scripting

Development Updated 2026.08.30

Paste the following prompt into your AI chat to install this skill:

Please install @user_3c6cb52e/unity-csharp-scripting-sh-hsr42w by following https://skillhub.cn/install/skillhub.md.

About this skill

Problem

Many MonoBehaviour bugs are not logic errors but misplaced plumbing: calling GetComponent in Update, moving rigidbodies outside FixedUpdate, exposing public fields to the Inspector, or losing coroutines when GameObjects are disabled. This skill targets Unity 6 (6000.0 LTS) with C# / .NET Standard 2.1, helping authors write deterministic, debuggable gameplay scripts.

How it works

  • Pick callbacks by purpose: Awake for cached references, OnEnable for subscriptions, Start for cross-object initialization, Update for per-frame logic, FixedUpdate for physics, LateUpdate for camera follow, OnDisable/OnDestroy for cleanup.
  • Access components safely: cache lookups in Awake and use TryGetComponent when a reference may be missing.
  • Expose Inspector fields deliberately: prefer [SerializeField] private over public fields so designers can tune values without scripts mutating them.
  • Sequence time-based logic reliably: scale per-frame changes by Time.deltaTime and use StartCoroutine for delays or multi-step behaviour with deterministic stopping.

Boundaries

This skill owns script lifecycle and C# plumbing, not rigidbody collisions, input reading, ScriptableObject config, or Animator parameters. Use the corresponding Unity subsystem skills for physics, input, shared data, or animation-driven behaviour.

Use Cases

  • In a Unity 6 character component, choose Awake, Update, and FixedUpdate callbacks, then cache Transform references.
  • Change public tunables to [SerializeField] private so the Inspector stays editable while external scripts cannot mutate them.
  • Implement a click reward with a 1-second coroutine delay and restart it in OnEnable after GameObject enable toggling.
  • Replace per-frame GetComponent calls and gameObject.tag string comparisons in hot paths with cached refs and CompareTag.

Best For

  • Client engineers owning Unity character behaviour scripts who want deterministic lifecycle and component caching rules.
  • Game designers maintaining Inspector panels who need clear field exposure without accidental mutation from other scripts.
  • Unity developers fixing lost coroutines and physics jitter in legacy projects who want to retime logic by correct callbacks.
  • Game tech leads reviewing Unity 6 C# code who need to check Update performance, serialization, and component access rules.