Handling UI with State Machine in Unity

One of my favorite use of State Machine design pattern is using states as different controllers of a game or an app. And today I’m going to present to you how you can implement such a thing in your Unity project! πŸ˜‰

As previously on AI subject with State Machine, we won’t change the implementation of State Machine and Base State scripts. They are staying the same. Maybe besides one reference and function call… 😜

Continue reading “Handling UI with State Machine in Unity”

Using State Machine for AI in Unity

Just a few days ago I made a post about implementing State Machine in Unity. I know that having design pattern implementation and nothing else is less useful, so I decided to make small AI that will use State Machine in a bigger context.

What this example is?

In the example that I’ve prepared we are making logic for units in some RTS game. By default, they are aggressive, and they are trying to get rid of the enemies nearby them.
We are going to have 2 types of units. First one will be a knight who will attack other groups. The second type will siege machine that will only be able to attack buildings. Both will have the same components, but parameters might differ a little bit.

Continue reading “Using State Machine for AI in Unity”

How to implement State Machine in Unity

Did you ever heard of term “design pattern”? Do you know what it means? Or do you know examples of it?

Today we will find out about one of the most important design patterns in game development! But beware, this might change you forever! 😱

What design pattern even is?

But first things first! What is the design pattern you might ask? I’m going to prepare a separate post only about that subject, so, for now, I have just a quick explanation.

A design pattern is a high-level idea or proposition on how you can write code. Each design pattern has its pros and cons, so you have to learn about them as much as you can to know where and when to use them in your project.

Continue reading “How to implement State Machine in Unity”