I want to select all the objects inside of a RTS style selection box.
Since I have originalmousePosition and currentMousePosition, Im looping though all the units and converting there coordinates to screen coordinates. From there Im testing weather the screen coordinates are located inside the box I drew. If the units are inside the box, it selects them.
I believe my code is “generally” right, but I dont think i have my bounds set up to represent the area inside the box. Any help please?
public static void selectMultipleObjects(Vector2 originalPos, Vector2 currentPos)
{
foreach(GameObject go in movableObjectsList) //represents all the movable units
{
var screenCoordinates = Camera.main.WorldToScreenPoint(go.transform.position);//convert the current object position to screen coordinates
//Find all the objects inside the box
if((screenCoordinates.x < originalPos.x && screenCoordinates.x > currentPos.x) && (screenCoordinates.y > originalPos.y && screenCoordinates.y < currentPos.y))
{
if(!DoesObjectExistInList(movableObjectsList, go))
{
SelectedObjects.Add(go);
}
}
}
}