Skip to content

Instantly share code, notes, and snippets.

@maoyeedy
Created February 19, 2026 14:22
Show Gist options
  • Select an option

  • Save maoyeedy/7cd7c91e8562ba689d0d03f178f5c004 to your computer and use it in GitHub Desktop.

Select an option

Save maoyeedy/7cd7c91e8562ba689d0d03f178f5c004 to your computer and use it in GitHub Desktop.

C# Naming

  • PascalCase: public members, methods, constants
  • _camelCase: private fields (static or instance)
  • PascalCase: public static fields and properties
  • camelCase: local variables and parameters

C# Syntax & Patterns

  • var for apparent local variables
  • Target-typed new() — never new TypeName()
  • Allman-style braces
  • Block-scoped namespaces, not file-scoped
  • Expression-bodied members for single-line properties/methods, not constructors
  • nameof() for strings (animation params, events, input actions)
  • Pattern matching over if-else chains
  • switch expression preferred over switch statement
  • Collection/object initializers where applicable
  • record / readonly struct for data carriers
  • Prefer static local functions
  • is null / is not null — never == null or != null
  • ??= null-coalescing assignment where applicable
  • Throw expressions: x ?? throw new InvalidOperationException()
  • sealed on classes not intended for inheritance
  • readonly on fields never reassigned after construction

Unity 6 (6000.3.x) API

  • rb.linearVelocity not rb.velocity
  • FindObjectsByType<T>() not FindObjectsOfType<T>()
  • FindAnyObjectByType<T>() not FindObjectOfType<T>()
  • RaycastNonAlloc for physics queries
  • TryGetComponent<T>() not GetComponent<T>() when component may be absent
  • CompareTag() not == for tag comparison
  • Physics.SyncTransforms not deprecated Physics.autoSyncTransforms
  • Never use GameObject.Find or FindWithTag — wire via Inspector or find at init only
  • New Input System only: Keyboard.current, Mouse.current — never legacy Input class
  • Implicit null check for object: if (gameObject) / if (!this) — never != null
  • [SerializeField] private fields + public property with private setter — no raw public fields
  • [DisallowMultipleComponent] on components that must not be duplicated per GameObject
  • Cache GetComponent in fields, never in Update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment