This video will give you a basic overview of the State Pattern and use it to create state machines in your games. The State Pattern is a programming design pattern, originally outlined by the famous "Gang of four". Each programming pattern can be thought of as a solution for a common problem in programming. Sometimes you will think to yourself, there must be a better way of doing this, and in those cases there is a good chance that one of the programming patterns will help you out.
The State Pattern is a way of changing the behavior of an object based on some internal state, so think of it like this, instead of having one big class with loads of if / else statements that end up getting so deep that you can't reason about them, you split up your script in several different states. Only one state can be active at a time, and that state determines the behavior of the object while it is in use.
For example you could have an Enemy with states like this. [IdleState.cs] [SearchState.cs] [AttackState.cs]. The way that we go about changing the current state is handled inside each state, so the [SearchState.cs] might say "if target is found then switch to [AttackState]". this is really cool because you can specify which states can move between each other and which ones cannot.
#GameDev #GameProgrammingPatterns #MadeInUnity #HauntedPS1