I am making a RTS prototype just for practice and I am having trouble selecting a unit. I am only able to select a unit if the rectangle made by the GUI.Box goes over the center of the cube. I would like instead to be able to have the unit selected the second that any part of it is inside the GUI.Box. Here is a snippet of the code where I am having trouble (in the update function):
foreach (GameObject unit in selectableUnits) {
screenPos = Camera.main.WorldToScreenPoint(unit.transform.position);
screenPoint = new Vector2 (_screenPos.x, Screen.height - _screenPos.y); //center
if (!backupBox.Contains(_screenPoint)) {
unit.SendMessage("OnUnselected", SendMessageOptions.DontRequireReceiver);
}
if (backupBox.Contains(_screenPoint)) {
unit.SendMessage("OnSelected", SendMessageOptions.DontRequireReceiver);
}
My trouble with the code is the screenPos. It is only taking the center of it. I have tried collider.extends but to no avail and I am stuck currently. Any help would be appreciated. Thanks :)
↧