Selection
Basic Unit Selection
In order to select units I created a new "Unit Manager" class in which I can store and manage all the unit's information. A unit is selected by ray-casting relative to the mouse position, then checking if the object hit was an AI unit. If so, then the unit's projector element is enabled to provide feedback of the player's action.
We need a way to select single units at once, however so to do this I created a list of units so that when a new unit is selected with the left mouse button then it loops through all currently selected units, disables them and then removes them from the list.
To select multiple units now, the player must hold down shift which disables the removing loop.
Finally, one of the most common features in an RTS that improves usability is a box select. A box select lets the player drag a box that selects any unit inside it, allowing for quick mass-selection compared to shift-clicking. This was achieved by checking if the mouse had been clicked and dragged a small distance which would then trigger the creation of the selection box. The selection box is created by storing the mouse's original position and creating a rectangle to the current mouse position. Visually, the box is made up of a 1px white image that is repeated. A lower opacity is used in the middle for clarity. The colour of the box can be changed in Unity's editor and can be transferred to in-game easily at anytime.
The only other features to add consist of combining the multiple ways to select units. Later on, when enemy ai are involved the function will have to be updated as to not select them.