Professional Documents
Culture Documents
health, attackDamage, defenseShield are hard coded values so all enemies have the same
values:
* What if we want to use the same EnemyController() component for all enemies while having
different types of enemies?
Check: ‘huge’ script containing all the enemy behaviours and select one using a value
contained in a public field. Using an ‘Enum’, for example, to easily select in the Inspector.
So, with a tick in the Inspector, the type is chosen. Or configuring it from outside.
Problems: hard to adjust the values. Need to expose too many parameters in the
Inspector or program a custom Inspector (not trivial). Moreover, these parameters will not keep
their values when stopping the playmode.
where the private variables to be used are initialized using the SO values, instead of being hard
coded:
so the enemy type is easily changed just by dragging the SO in the Inspector’s field slot:
And then values can be changed and preserved while in playmode to adjust the game design:
Remember that you can hide a public variable in the inspector, to avoid accidental changes,
using the [HideInInspector] attribute. In the opposite, you can expose a private variable in the
Inspector, using the [SerializedField] attribute.