RTS Drag Selection Box Using Unity UI

RTS Drag Selection Box Using Unity UI

Work is already underway on a prototype of Project Astra (working title), a space strategy game that I'm currently building. Using the Unity game engine, I've been prototyping turret functionality, a camera control system, and a unit selection system. Originally, I was using PlayMaker's visual scripting FSM system, which was quite fun and easy to use. However, there were some things which I felt could be done a little more quickly through direct coding, and I found that I was constantly waiting for 3rd party asset vendors to create up-to-date PlayMaker actions for their assets.

Wanting to become more intimate and familiar with Unity's API, I've decided to delve into directly programming the functionality I want. Even though I just started learning to program for the first time last year, I've been finding it extremely engaging so far. There hasn't been anything I haven't been able to figure out yet thanks to Unity's extensive documentation and ALL the various people who have posted Unity and programming tutorials.

For my first experimental game, I was using the Daikon Forge GUI system, but development on that GUI extension has been discontinued. I've been learning the Noesis GUI system in the hopes of using it for Project Astra, especially because of its resolution independence using vector graphics, XAML, and the WPF API. However, Unity just released the beta of its new GUI system, and I've been watching the tutorials and reading the documentation on it for the past day or so. Keeping my GUI code and mechanics separate has made it relatively easy to try out different GUI systems.

I've successfully implemented multiple unit selection functionality, although it required lots of testing to make sure I accounted for every possible situation and click combination. Using Unity's old GUI system, I was able to get the box itself to appear correctly no matter which direction it was created in, but was having problems figuring out how to do the same with Unity's new GUI system. I made a post on the beta section of Unity's forum to see if I could get some help, but I ended up figuring it out anyway. If you want to see the problem and solution, head over here: https://forum.unity.com/threads/rts-style-drag-selection-box.265739/

By the way, I'm using the Modular Space Ship Pack by Retora from the Unity Asset Store for prototyping purposes, as you can see in the screenshot of the selection box example above. For some reason, the mouse cursor wasn't included during the screenshot.