Unity GUI has a great drag and drop interface for calling public functions from your code when certain events are triggered. You can see this when using a UGUI Button script, it has an interface for calling your functions when the button is clicked. I was looking into a way to replicate this kind of drag and drop interface for my own projects and found that Unity has this functionality built in. There’s no need for custom UnityEditor scripts. I figured this out while digging through the source code for the Unity UI system.

unity_button_events
An Example of UGUI Button OnClick events

The beauty of having this drag and drop functionality is that it makes it easier to modify the logic of your project without having to dig into code to make changes. By partnering this with a set of specialized components, you can easily create a system for modifying aspects of your project without having to dig into code.

It’s actually quite easy to setup something like this for your own project. This is great for UI Events but also for game events (collecting items, level complete, etc.). To accomplish this all you need is to make use of the UnityEvent class. Just to be clear, these aren’t the same as the standard C# Event system.

Continue Reading…