public void Update() { if (isActive) { // If we press the left mouse button, begin selection and remember the location of the mouse if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject()) { isSelecting = true; mousePosition1 = Input.mousePosition; foreach (var selectableObject in context.GetPlayerObjectPool().GetPlayerSelectableObjects()) { Deselect(selectableObject); } context.GetBuildChoiceUpdater().SetMainObjectForHud(null); } // If we let go of the left mouse button, end selection if (Input.GetMouseButtonUp(0) && isSelecting) { IPlayerSelectableObject mainObjectForHUD = null; foreach (var selectableObject in context.GetPlayerObjectPool().GetPlayerSelectableObjects()) { if (IsWithinSelectionBounds(selectableObject.GetGameObject())) { selectableObject.Select(true); if (mainObjectForHUD == null || selectableObject.GetSelectionPriority() < mainObjectForHUD.GetSelectionPriority()) { mainObjectForHUD = selectableObject; } } else { selectableObject.Select(false); } } context.GetBuildChoiceUpdater().SetMainObjectForHud(mainObjectForHUD); isSelecting = false; } // Highlight all objects within the selection box if (isSelecting) { foreach (var selectableObject in context.GetPlayerObjectPool().GetPlayerSelectableObjects()) { if (IsWithinSelectionBounds(selectableObject.GetGameObject())) { Select(selectableObject); } else { Deselect(selectableObject); } } } } }