The Seek-Health
state occurs when the enemy runs low on health and can restore it by collecting a medikit. This state is unlike most others, in that, it can be reached or entered from any state. The entering of this state doesn't depend on its relationship to others, but only on the player's health. Specifically, this state should be entered when the enemy's health is reduced beyond a minimum floor. As a result of this configuration, be sure to hook up the Seek-Health
animation state in the Mecanim graph to the Any State node that allows the run animation to be triggered in any state, as shown here:
Each enemy maintains a Health
variable; this variable is adjusted either up or down, depending on whether the enemy finds a medikit or is attacked. The change occurs inside the method ChangeHealth
, and this is where we can determine whether a SeekHealth
state must be initiated. The ChangeHealth
function...