[SerializeField] private int num;
public int Num => num;
Why would someone do this to access a private variable? Wouldn’t it be better to just say ‘public int num;’? Or is it better practice?
[SerializeField] private int num;
public int Num => num;
Why would someone do this to access a private variable? Wouldn’t it be better to just say ‘public int num;’? Or is it better practice?
Properties provide encapsulation and future proofing that public variables don’t. Traditionally, Unity was also incapable of serializing properties but I believe that’s changed recently though with some quirks. There’s really no reason to ever have a public member variable on a class.