//Controls all the left mouse clicks private void LeftMouseClick() { if (Input.GetMouseButtonDown(0)) { //makes mouse clicks not bounce through UI elements if (EventSystem.current.IsPointerOverGameObject()) { return; } //deselects already selected characters before making a new selection for (int i = 0; i < selectedAgents.Count; i++) { selectedAgents[i].gameObject.GetComponent <SelectedInteractable>().DisableSelection(); } agentInventoryPanel.gameObject.SetActive(false); selectedAgents.Clear(); dragSelecting = true; playerMouse = Input.mousePosition; //draws a raycast to find new selectable character Ray ray = cam.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100, selectableMask)) { if (hit.transform.tag == "Unit") { AgentController newAgent = hit.transform.GetComponent <AgentController>(); if (newAgent.IsActive) { selectedAgents.Add(newAgent); } if (selectedAgents.Count > 0) { selectedAgents[0].gameObject.GetComponent <SelectedInteractable>().EnableSelection(); } } } } if (Input.GetMouseButtonUp(0)) { foreach (GameObject selectable in GameManager.instance.AllActivePlayers) { if (IsWithinSelectionBounds(selectable)) { AgentController newAgent = selectable.transform.GetComponent <AgentController>(); if (newAgent.IsActive) { selectedAgents.Add(newAgent); selectable.GetComponent <SelectedInteractable>().EnableSelection(); } } } dragSelecting = false; } //Display item of selected agent at position 0 if (selectedAgents.Count > 0) { agentInventoryPanel.gameObject.SetActive(true); if (selectedAgents[0].HeldItem != null) { itemIcon.SetSelectedItem(selectedAgents[0]); } else { itemIcon.ResetIcon(); } } }