← All posts
postApril 21, 2026
Structuring C# Classes in Unity
#csharp#unity#architecture

csharp
using UnityEngine;
public class PlayerController : MonoBehaviour
{
// 1. Serialized fields (Inspector-visible)
[SerializeField] private float moveSpeed = 5f;
[SerializeField] private float jumpForce = 8f;
// 2. Private state
private Rigidbody _rb;
private bool _isGrounded;
// 3. Unity lifecycle
private void Awake() { _rb = GetComponent<Rigidbody>(); }
private void Update() { HandleInput(); }
private void FixedUpdate() { ApplyMovement(); }
// 4. Private helpers
private void HandleInput() { /* ... */ }
private void ApplyMovement() { /* ... */ }
}