// Handle unit selection private void leftClick() { if (SelectedUnitGroup != null) { SelectedUnitGroup.SendMessage("OnUnselected", SendMessageOptions.DontRequireReceiver); SelectedUnitGroup = null; } // Cast ray to see if object hit is selectable Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { if (hit.transform.gameObject.tag.Contains(vars.selectable_tag) && hit.transform.gameObject.tag.Contains(vars.friendly_tag)) { // Send OnSelected signal to Unit / Unitgroup hit.transform.gameObject.SendMessage("OnSelected", SendMessageOptions.DontRequireReceiver); // Add unit group to selected group if (hit.transform.gameObject.tag.Contains(vars.unitgroup_tag)) { SelectedUnitGroup = hit.transform.gameObject.GetComponent <UnitGroupFriendlyScript>(); } else // Add unit's group { SelectedUnitGroup = (UnitGroupFriendlyScript)hit.transform.gameObject.GetComponent <UnitScript>().unitGroupScript; } } } }
// Handle unit selection private void leftClick() { if (SelectedUnitGroup != null) { SelectedUnitGroup.SendMessage("OnUnselected", SendMessageOptions.DontRequireReceiver); SelectedUnitGroup = null; } // Cast ray to see if object hit is selectable Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { if (hit.transform.gameObject.tag.Contains(vars.selectable_tag) && hit.transform.gameObject.tag.Contains(vars.friendly_tag)) { // Send OnSelected signal to Unit / Unitgroup hit.transform.gameObject.SendMessage("OnSelected", SendMessageOptions.DontRequireReceiver); // Add unit group to selected group if (hit.transform.gameObject.tag.Contains(vars.unitgroup_tag)) { SelectedUnitGroup = hit.transform.gameObject.GetComponent<UnitGroupFriendlyScript>(); } else // Add unit's group { SelectedUnitGroup = (UnitGroupFriendlyScript)hit.transform.gameObject.GetComponent<UnitScript>().unitGroupScript; } } } }