Creating a turn-based battle system
Conventionally, a state is only required to have a method for handling state-specific logic, but a more complete implementation will have Enter and Exit methods and separate methods for handling input and checking for state changes. This is especially useful in Unity when you need to separate physics logic that needs to be fired in FixedUpdate versus other state logic that can go in the regular Update function in your client script.
For our example, we’ll be using the whole bundle – enter, exit, input-handling, and state transition methods, which are going to help us write a more robust (and customizable) state-handling system.
Defining abstract and base states
In the Scripts folder, create a new C# script named State and update its code to match the following code block. This class will serve as our blueprint for all states in the game, even if they are used in different state machines. We’ll be using coroutines...