Unity C# Coding Conventions & Best Practices
Article 1 of the Unity C# Coding Series

This guide outlines standard naming conventions, member ordering, and Unity-specific coding practices to help maintain clean, consistent, and scalable code across Unity projects.
1 ✅ Naming Conventions
This is the first and the foremost thing you should improve in your code. This alone holds the power to make your code look organised and professional.
🔹 Class, Interface, and Enum Names
- Use PascalCase
public class GameManager {}
public interface IInteractable {}
public enum WeaponType { Sword, Bow, Gun }
🔹 Fields
Private fields:
camelCasewith_prefix (which I do not prefer or recommend due to its ugly look and unnecessary effort in finding a variable when coding; so, I simply use camelCase without the underscore)Public fields:
PascalCaseConstants:
ALL_CAPS_SNAKE_CASE
[SerializeField] private float _movementSpeed;
public string PlayerName;
private const int MAX_LIVES = 3;
🔹 Methods
- Use PascalCase for all method names
public void TakeDamage(int amount) {}
🔹 Local Variables & Parameters
- Use camelCase
void Move(float speed)
{
float adjustedSpeed = speed * 2f;
}
🔹 Properties
- Use PascalCase, and expose only when necessary
public int Health { get; private set; }
2 🧱 Member Ordering (Inside a Class/Script)
This one is more on the beautification side but beautiful_code = readable_code💡
Organize class members in the following order:
| Member Type | Order Description |
|---|---|
| Constants | 1️⃣ At the top |
| Static Fields / Methods | 2️⃣ Immediately after constants |
| Instance Variables | 3️⃣ Public → Protected → Private |
| Unity Methods | 4️⃣ Awake, Start, Update, etc. |
| Public Methods | 5️⃣ Methods exposed to other classes |
| Protected Methods | 6️⃣ Meant to be overridden in subclasses |
| Private Methods | 7️⃣ Internal logic |
| Coroutines / Handlers | 8️⃣ Bottom of the class |
🧪 Example
public class PlayerController : MonoBehaviour
{
// 1. Constants
private const float Gravity = 9.81f;
// 2. Static Fields and Methods
private static int _globalScore;
public static void ResetScore()
{
_globalScore = 0;
}
// 3. Instance Fields
public float speed;
protected Rigidbody rb;
[SerializeField] private int _health;
private bool _isAlive;
// 4. Unity Event Methods
private void Awake()
{
rb = GetComponent<Rigidbody>();
}
private void Start()
{
_health = 100;
_isAlive = true;
}
private void Update()
{
Move();
}
// 5. Public Methods
public void TakeDamage(int amount)
{
_health -= amount;
if (_health <= 0) Die();
}
// 6. Protected Methods
protected virtual void Die()
{
_isAlive = false;
}
// 7. Private Methods
private void Move()
{
rb.velocity = new Vector3(Input.GetAxis("Horizontal") * speed, rb.velocity.y, 0);
}
private bool IsAlive()
{
return _isAlive;
}
// 8. Coroutines / Event Handlers
private IEnumerator FadeOut()
{
yield return new WaitForSeconds(1f);
}
}
3 🔐 Access Modifiers
Always declare your variables and functions with access modifiers (
public,private,protected,internal)Prefer
privatefields and expose them through public properties or[SerializeField]Avoid
publicfields unless absolutely necessary
[SerializeField] private int _ammoCount;
public int AmmoCount => _ammoCount;
4 ✏️ Formatting & Style
🔹 Braces
- Use Allman style: braces go on a new line
if (isActive)
{
Activate();
}
🔹 Variable Declarations
- One variable per line
private int _score;
private float _speed;
🔹 Spacing
- Add blank lines between logical code blocks and method definitions
📌 Tip: Regions
Keep Related Things Close Together
Use #region to logically group related code. This is especially helpful when your code stretches for 100s of lines which it will when following all these formatting standards.
Example: If you have a Jump() method and jumpForce variable, keep them near each other.
#region Jump
[SerializeField] private float jumpForce;
private void Jump() { ... }
#endregion
General practice: -
Region Unity Methods for
Awake,Start,Update, etc.Region Public Methods for public access methods
Region Helper Functions or Utility for private access methods that help other public functions
Region Inherited or Overrides for OOP functions
Region Multiplayer for related code, public or private, everything and sub-regions for RPCs, public, helper, inherited methods, etc.
Region names simple suggestions. You shall name specific regions based on your grouping.
5 🗂️ File Structure & Namespaces
One public class per file
File name should match the class name exactly
Use namespaces to reflect folder hierarchy and logical organization (needed for larger codebases where your class names might conflict with Unity’s classes)
namespace Game.Enemies.Bosses
{
public class DragonBoss {}
}
🔗Refer this super informative blog for more in-depth guidelines.



