Creating an 'old-school' FPS game. At this stage, I'm focusing on the game's enemies.
Enemies in game have multiple 'behaviour' states and animations that go with each. Behaviour states are what the enemy does at one given time. The main States are Spawn, See, Attack, Pain, and Death.
Spawn: Enemy spawns in (gameobject is enabled). Enemy waits 2 secs, and then proceeds to do its first task.
See: The enemy has detected the player and will proceed to a position where it can attack the player.
Attack: Is in attack position, starts to attack the player. (Attack!)
Pain: Has been hit and is knocked back (stunned).
Death: Health <= 0. The enemy has been defeated.
There are plans to have more behaviour states, like, for example, being Frozen or on Fire. Currently, I'm using a switch statement to handle all the states. The plan is to have around 7 enemies in the game. If things get out of hand, and code becomes messy, I'll have to rethink and change this. But for now, this will do.
The 'brainhead' enemy is a simple melee attacking enemy (no ranged attacks).
The brainhead enemy starts off in the Spawn State, where it will calculate the distance between the player and itself. If the player is less than 10 units away, the enemy 'sees' the player.
It then sets its destination to be the player (NavMeshAgent). A CheckSphere bool is then calculated to see if it is touching the player. If it is, then start to attack the player. If not, and the player is over 50 units away from the enemy, the enemy returns to its Spawn State (stops following player).
Brainhead has two attacks (they deal the same amount of damage and is chosen in its OnEnable method), punches and a headbutt. The enemy will start attacking the player. If the player exits the enemy's CheckSphere, it will finish its attack and return to its Spawn State, which in turn, will quickly change to its See State (because player's distance is less than 10 units away from the enemy).
A shrivelled up gherkin