I’m using some booleans for the activation of animations of two characters. This is my code so far, it works but I think I will have spaguetti code after a bit.
Is there any better way on how to do this? Maybe a cleaner and more manageable way?
You could combine each pair into a single call outside of the if statements, and only the ones specific to each condition are called within the if statements. That is, “damaged”, “matchText”, “timerUp”, and “dead” are all set no matter what. Also, “win” and “winGame” are both very similarly named; is that a typo or just a poor naming scheme?
(Aside from the animator calls, setting timerCount and stateMatch.SetActive are common to both, and could be moved outside the if statements)
You should have a Zombie class that references an animator. It should listen to an Event (ScoreChanged) from a Score class. Then change itself to dead/damaged/etc.
Ideally, the Zombie class would also have a state machine of some kind, so you can set the animator to false automatically when it exits the state. Like this simple one:
IEnumerator DeadState()
{
// On Enter
animator.SetBool("IsDead", true);
// On Update
while (state == State.Dead)
{
yield return null;
}
// On Exit
animator.SetBool("IsDead", false);
}