<!-- skill: Unity Game | version: 1.0.0 | description: Build Unity games with C# — scenes, prefabs, input, builds | category: Games -->

## Instructions
- One scene per level/menu; a `MainMenu`, `Game`, `GameOver` split beats one mega-scene.
- Prefabs for everything reusable (player, enemies, pickups); never duplicate scene objects by hand.
- C#: one `MonoBehaviour` per file, matching filename. Serialize fields (`[SerializeField]`) instead of `Find()` calls.
- New Input System for controls; design for keyboard+gamepad from the start.
- Game state in a `GameManager` singleton (or ScriptableObjects); scenes talk through it, not direct references.
- Version control: Unity `.gitignore` (Library/, Temp/, *.csproj), force text serialization, visible meta files.

## Examples
- 2D platformer: player prefab (Rigidbody2D + controller script), tilemap level, coin prefabs with trigger pickup.
- High-score menu: `PlayerPrefs` persistence + scene switch on button.

## Workflows
1. Project (2D/3D template) → folders: Scenes, Scripts, Prefabs, Sprites, Audio.
2. Prototype the core loop first (move, collide, win/lose) with gray boxes.
3. Replace placeholders with real art/audio; add menus + persistence.
4. Playtest the build (not just editor): `File → Build` for the target platform.
5. Iterate on juice last: particles, screenshake, sound.

## Templates
```csharp
// PlayerController.cs — frame-rate independent movement
using UnityEngine;
public class PlayerController : MonoBehaviour {
    [SerializeField] float speed = 6f;
    Rigidbody2D rb; Vector2 move;
    void Awake() => rb = GetComponent<Rigidbody2D>();
    void Update() => move = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")).normalized;
    void FixedUpdate() => rb.MovePosition(rb.position + move * speed * Time.fixedDeltaTime);
}
```

## Tools
- Unity Hub + Editor (note: heavy on a Pi — develop on desktop, target Pi or export WebGL).
- SARAH can manage docs/scripts/assets around the project; builds happen in the Editor.

## Advanced
- Kill Instantiate/Destroy in hot paths: object pools (bullets, particles, enemies) pre-warmed at scene load.
- Data-driven design: ScriptableObjects for items/levels/enemies (designers tweak assets, not code); save files as JSON via `JsonUtility`.
- Rendering: URP + per-platform quality tiers; forward renderer for mobile/VR; light layers + reflection probes before adding realtime lights.
- UI at scale: one Canvas per update-frequency group, `CanvasGroup` fades, TextMeshPro always (never legacy Text), addressable or Resources-free loading.
- Debugging: Profiler (CPU/GPU/memory modules), Frame Debugger for draw-call mysteries, `Debug.Break` + Pause for frame-perfect inspection.
- Builds: Build Profiles per platform, Scripting Backend IL2CPP for release, version in `ProjectSettings` (bundleVersionCode bumps or stores reject).
- Troubleshooting: pink materials → shader/URP mismatch, reimport; missing prefab links → never rename outside Unity; physics tunneling → Continuous collision + smaller fixed timestep.

## Documentation
- Unity manual: https://docs.unity3d.com/Manual
- Scripting API: https://docs.unity3d.com/ScriptReference
