Unity Tip: Don’t Always Use Update

The Update function in MonoBehaviour is where you’ll end up running a lot of you game code. However, it’s always worth asking yourself does the code need to be running every frame? Some parts you can get away with running a few times a second or event every few seconds. Every time you’re building something into Update, understand if this is where it must be.
Level of detail code is a very obvious one that you might only want to update every second or so. I’ll usually run InvokeRepeating for that.

Unity Tip: Don’t Use Public to Show Fields in the Unity Editor

If you want to see a variable appear in the Unity editor, you don’t need to make it public. You can use [SerializeField] / @SerializeField to do this and keep your variable private.

private var _myPrivateString = "You can see this in the Unity Editor";
private string _myPrivateString = "You can also see this in the Unity Editor";

SerializeField is also important if you’re encapsulating properties in scripts… Properties don’t appear in the Unity editor by default, but if you’re using custom editors, you’ll soon slip on this problem…

private bool _hiddenValueA = false;
private bool _hiddenValueB = false;

//_hiddenValueA IS NOT serialised so when you press play it resets!
public bool valueA
    get{return _hiddenValueA;}
    set{_hiddenValueA = value;}

//_hiddenValueB IS serialised so when you press play it is saved.
public bool valueB
    get{return _hiddenValueB;}
    set{_hiddenValueB = value;}