---
trigger: glob
globs: Assets/**/*.cs
---

# Unity 6 (C#)

- Serialize private fields with `[SerializeField] private float speed = 5f;` instead of public fields. Validate in `OnValidate`.
- Cache components in `Awake` (`TryGetComponent`), subscribe to events in `OnEnable`, unsubscribe in `OnDisable`. No `GetComponent`, `Find`, or `Camera.main` lookups in `Update`.
- Physics in `FixedUpdate` with `Rigidbody` (`linearVelocity` in Unity 6); frame logic in `Update` scaled by `Time.deltaTime`.
- Data and config in `ScriptableObject` assets; avoid singletons holding game state where an SO or a scene service works.
- Input with the Input System package (generated C# class or `PlayerInput` actions), not the legacy `Input.GetKey`.
- Async: `Awaitable` / `async` methods (Unity 6) or coroutines; cancel with `destroyCancellationToken`.
- Avoid per-frame allocations (LINQ, string concat, `new` lists); use object pooling (`UnityEngine.Pool.ObjectPool<T>`).
- Assets loaded via Addressables if the project uses them; never `Resources.Load` in new code without reason.
- Namespaces per feature; one MonoBehaviour per file with a matching name.
- Wrap editor-only code in `#if UNITY_EDITOR`.

## Don't
- Don't edit `.meta`, `.unity`, or `.prefab` YAML by hand.

## Done when
No compiler warnings in the Console, and EditMode/PlayMode tests (Test Runner) pass.
