Drag and Drop in Unity

Recently I got a question to help solve some problem in Drag and Drop implementation in Unity. So as a bonus I decided to make my example of how to implement that! ?

Drag and Drop mechanic is often used in mobile games, but you can also encounter then in PC games. But thanks to Unity’s Event System this implementation will work fine on both platforms! ?

So let’s get started!

First of all, we need to create UI for our example! It will look like that:

UI setup example

Great! We are over the hardest part!  ?

Continue reading “Drag and Drop in Unity”

Events or Interfaces Listeners?

If you’re reading my posts and you’re checking my public repositories, you might notice that I’m implementing UI with Events that are passing input to the controllers. This is really convenient as you have a clear separation between logic and display layers.

Background

To recap what this UI implementation looks like, let me first explain where it comes from.

From the beginning, I always tried to make my code modular, but I couldn’t grasp how to do it in a really clean way. It was literally taking me years, multiple projects and few programming languages to get to digging into design patterns finally. With them, I started to understand more of what I was doing and how easy it was to start taking care of your code and separate different layers from each other! ?

Continue reading “Events or Interfaces Listeners?”

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”