Unity provides a funtion that allows your MonoBehaviors to be alerted when values are changed on it in the inspector. The OnValidate
method is invoked every time you modify a value in the inspector (only the inspector, changes to the value via code don’t publish any alerts). This makes it possible to validate your modifications in a way that makes sense. In our example we’ll use a min and max value where the min/max function as limits on one another so the min value can’t exceed the max value.
An example that logs a notification every time you modify the value might look like this:
|
|
Join the World of Zero Discord Server: https://discord.gg/hU5Kq2u