Variable attributes
The [Range] attribute can be added to an integer or floating-point field to convert it into a slider in the Inspector window. We can provide minimum and maximum values, thus limiting the range that the value can contain.
Normally, if a variable is renamed, even if we do a refactor through our IDE, then the values are lost as soon as Unity recompiles the MonoBehaviour and makes the appropriate changes to any instances of the component. However, the [FormerlySerializedAs] attribute is incredibly helpful if we want to rename a variable that has been previously serialized, since it will copy the data from the variable that was named within the attribute into the given variable at compile time. No more lost data due to renaming ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access