---
description: Unity C# conventions
globs: ["Assets/**/*.cs"]
---

# Unity (C#)

- Unity 6 LTS, C# 9. Namespaces mirror folders under `Assets/_Project/Scripts`.
- Serialize private fields with `[SerializeField] private`; don't make fields public just for the Inspector.
- Cache component references in `Awake`; never call `GetComponent`, `Find`, or `Camera.main` inside `Update`.
- No allocations in hot paths: avoid LINQ, string concatenation, and `new` in `Update`/`FixedUpdate`. Use object pools for spawned objects.
- Physics in `FixedUpdate`, input and visuals in `Update`. Use the new Input System.
- Config and shared data in ScriptableObjects; events via C# events or ScriptableObject event channels instead of singletons.
- Use `async`/Awaitable or coroutines for timed sequences; always cancel on `OnDisable`.
- Never edit `.meta` files or scene YAML by hand.
- Mark editor-only code with `#if UNITY_EDITOR` or put it in an `Editor/` folder.
