A couple of weeks ago, we improved our UI and displayed more info on the buildings (with an info panel and healthbars).
Today, we’re going to continue on this topic and improve our selection mechanism — we’ll do three things:
In a previous tutorial, we set up a basic selection system that allows to select units by either dragging a box around them on the screen or by clicking on them directly. We see which units are selected because they have a selection circle and a healthbar, but it would be nice to have a complete list of all the units currently selected somewhere on screen. In particular, this will be very useful when we start moving the camera and possibly have selected units that are no longer in the viewport.
To avoid having too many blocks in this list, we will group units per unit type; so for example if we select 1 House and 2 Towers, we will have 2 items: one for the House with a count of 1 and one for the Towers with a count of 2. Eventually we will use the unit icons — for now, we’ll simply add a text with the name of the unit type:
To implement this, we have to:
UIManager
and UnitManager
scripts to integrate this new feature to the current selection systemThe first part is very similar to what we’ve done in previous tutorials and it’s quite dependent on the feel you want for your game, so I won’t give explicit details about this here. The important thing is just that my SelectedUnitDisplay prefab has two children with Text components on them: the “Count” and the “Name” to show respectively the current amount of selected instances and the unit type.
#games #development #unity #tutorial #csharp