Well, I can at least give you a quick technique for selecting the units. You need to put a trigger collider over each unit with this script attached:
var selected : boolean = false;
var master : MovementScript;
function OnMouseDown()
{
selected = true;
master.SelectMe(this);
}
Naturally, the larger the trigger collider the easier it will be to click on it. Also, MovementScript is the name of a script that would hold an array and function like this:
var units : UnitScript[];
function SelectMe(var hit : UnitScript)
{
for (stuff in units) {
if (stuff == null) {
stuff = hit;
break;
}
}
}
The script on the unit would be the UnitScript.
Once they’re selected, all you’d need to do is create a function for movement, targeting, and attacking things that the movement script can send the unit script based on inputs.
I’m making a tutorial series about this in half a month or so, too…
If you want to drag-select multiple units as in many RTS games, you could pull that off by using Physics.OverlapSphere.
Of course there doesn’t appear to be a corresponding Physics.OverlapBox, but sure you could fake that in a number of ways. Not sure if you dynamically create a trigger after dragging it’s dimensions out with a rectangular bounds, whether or not Collider.OnTriggerEnter fires or not. Might be something to experiment with.
Thank you for this but function SelectMe(var hit : UnitScript) does not seem to work - unexpected var
and something else - does it work for anyone - is it me?