As soon as i looked at the code challenge i IMMEDIATLY wanted to swap it out for observer. so much so that i thought the challenge was a “set up” to explain an observer pattern use case. i wont rewrite the code but i would have done the following…
Enemy
-
even if i was going to cache the character id do it in awake to avoid initialization or race conditions later, but id just scrap the cache in start in this case.
-
swap attack to an event/Action( id probably prefer to use an event becuase i like having unity actions for an audio manager, but if itsa bigger game id use an event because i think they have better performance…not 100% sure on that).
Character
-
either serialize the health field or move it to its own class depending on complexity of health system
-
removed the animator, and audio variables and put them in some sort of audio script
-
implement iKnockbackable, and iDamagable interfaces on character(or health script for iDamagable if we did need the health system to be more robust)
-
Moved the methods to their relevant scripts
-
subscribe the methods to the Attack event( via OnEnable/OnDisable)