gamedev-skills/unity-csharp-scripting
> (Awake/OnEnable/Start/Update/FixedUpdate/LateUpdate), GameObject and component access, coroutines, and Inspector serialization. Use when creating or editing .cs scripts in a Unity project, or when the user mentions MonoBehaviour, Start/Update, GetComponent, SerializeField, coroutines, or "Unity script".
npx skills add https://github.com/gamedev-skills/awesome-gamedev-agent-skills --skill unity-csharp-scripting
Write correct, idiomatic gameplay scripts in Unity 6. Get the lifecycle, component
access, serialization, and coroutines right so behaviour is deterministic and the
Inspector stays useful. Targets Unity 6 (6000.0 LTS), C# / .NET Standard 2.1.
MonoBehaviour: choosing the right lifecycle callback,reading/caching components, exposing fields to the Inspector, or running timed logic
with coroutines.
*.cs files, an Assembly-CSharp or *.asmdef, and aProjectSettings/ folder.
When *not* to use: moving rigidbodies / collision response → unity-physics; reading
player input → unity-input-system; shared data assets / config → unity-scriptableobjects;
Animator parameters → unity-animation. This skill owns the *script lifecycle and C#
plumbing*, not those subsystems.
Awake (cache references, runs once onload), OnEnable (subscribe to events), Start (init that depends on other objects'
Awake), Update (per-frame logic/input polling), FixedUpdate (physics), LateUpdate
(camera follow after movement), OnDisable/OnDestroy (unsubscribe/cleanup).
Awake — never call GetComponent every frame.[SerializeField] private, not public fields, so other codecan't mutate them but designers can edit them in the Inspector.
Time.deltaTime in Update (and Time.fixedDeltaTimesemantics are automatic in FixedUpdate).
start them with StartCoroutine and stop them deterministically.
in the Inspector update as expected, and watch the Profiler if Update is hot.
using UnityEngine;
[RequireComponent(typeof(Rigidbody))] // auto-adds the dependency, prevents null refs
public class PlayerController : MonoBehaviour
{
[SerializeField] private float moveSpeed = 6f; // editable in Inspector, private in code
private Rigidbody _rb; // cached, not fetched per frame
private void Awake() => _rb = GetComponent<Rigidbody>(); // cache once on load
private void Update()
{
// Per-frame, non-physics work. Scale by deltaTime so it is frame-rate independent.
transform.Rotate(0f, 90f * Time.deltaTime, 0f);
}
private void FixedUpdate()
{
// Physics work belongs here (fixed timestep). See the unity-physics skill.
_rb.MovePosition(_rb.position + transform.forward * moveSpeed * Time.fixedDeltaTime);
}
}
TryGetComponent// Avoids allocating a null and is clearer than GetComponent + null check.
if (other.TryGetComponent<Health>(out var health))
health.Apply(-10);
[SerializeField, Range(0f, 1f)] private float volume = 0.8f; // slider
[SerializeField] private string playerName = "Hero"; // private but serialized
[System.Serializable] // REQUIRED for a plain class to serialize/show
public class Stats { public int hp = 100; public int mana = 50; }
[SerializeField] private Stats stats = new(); // nested struct-like data in the Inspector
private void Start() => StartCoroutine(FlashThenHide());
private System.Collections.IEnumerator FlashThenHide()
{
yield return new WaitForSeconds(0.5f); // wait half a second of game time
GetComponent<Renderer>().enabled = false;
yield return null; // resume next frame
}
GetComponent in Update — it searches every frame and tanks performance. Cache thereference in Awake/Start.
Update — moving a Rigidbody with forces or MovePosition outsideFixedUpdate causes jitter and timestep-dependent behaviour. Read input in Update,
apply physics in FixedUpdate.
Start order across objects — Start runs after *all* Awakes, but orderamong Starts is undefined. Do cross-object wiring in Start, self-setup in Awake.
public fields just to show them in the Inspector — that also lets any script mutatethem. Use [SerializeField] private instead.
gameObject.tag == "Enemy" allocates a string and is slower; usegameObject.CompareTag("Enemy").
killed; re-StartCoroutine in OnEnable if it must survive toggling.
Update never runs before Start, but the *first* Update can run on the sameframe as Start** — guard against not-yet-initialised fields if you split setup oddly.
CustomYieldInstruction, stopping by handle, WaitUntil/WaitWhile), read
references/lifecycle-and-coroutines.md.
(https://docs.unity3d.com/Manual/execution-order.html) and ScriptReference/MonoBehaviour.
unity-physics — Rigidbody, collisions, and FixedUpdate motion.unity-input-system — reading player input into these scripts.unity-scriptableobjects — sharing data/config between scripts without singletons.Take gamedev-skills/unity-csharp-scripting from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.