Final Part. Variables
- Sam Walet
- 3 jun 2022
- 2 minuten om te lezen
Last but not least I would like to spend a little time on variables. You should be conscious of which variables you show in the inspector and which you hide away. All variables in the inspector should be important otherwise you should just use [HideInInspector]. Because we find or instantiate the sources, detectors and modifiers at runtime I have hidden all their lists from view.

I also always make two headers, one for references and one for settings. References are needed for the script to run but should generally only be touched if they are null in which case the script probably wonāt run correctly while settings should be changed to change the behavior of the script. If you have a lot of settings you can make more headers to separate different types of settings. Always use tooltips if a variable name leaves ambiguity about what the variable does, it can never hurt to have some extra information there if the designer is confused.

Here you will see another useful feature that is somehow not standard in the unity engine. A readonly flag. This means that it will display the variable in the inspector but you wonāt be able to change the value. This is very useful for values that you often need for debugging but should not or can not be changed.

Luckily it is very easy to create this yourself.

One final tip concerning variables: animationCurves. Animation Curves allow you to have a graph as a variable which can be used for for example speed ramping or in the case of this project, the fall off of the source, meaning that it controls the strength of oxygen from a source depending on distance.
I hope this tutorial was of use to you and learned some new tricks and methods to write better code. I have been using some of these for a long time while I learned others myself while creating this system. I will leave you with a little example of the kind of behavior this system can create.




Opmerkingen