Improving the quality of your C# scripts in Unity can make them integrate better with the editor, improve their readability and make them more maintainable. I’ve put together a list of techniques to use when writing Unity scripts that will improve the quality of your code.

Tl;dr: Use [SerializeField], use enums, use [Header] and [Tooltip], use the context field in Debug calls, use /// comments

1. Limit variable access by using [SerializeField] instead of public fields

Exposing variables to the inspector is very useful, but oftentimes these variables should be exposed to the inspector and to nowhere else. What happens when a field is marked public is that it becomes editable…


Software developer, game designer, musician.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store