public void RoamInputs() { m_MouseRay = m_MainCamera.ScreenPointToRay(Input.mousePosition); m_LeftMouseDown = Input.GetMouseButtonDown(0); // Clicked on a character if (Physics.Raycast(m_MouseRay, out m_MouseWorldRayHit, Mathf.Infinity, 1 << 9)) { Unit rayHitUnit = m_MouseWorldRayHit.collider.GetComponent <Unit>(); if (m_LeftMouseDown) { if (rayHitUnit != null) { if (rayHitUnit != m_SelectedUnit && rayHitUnit.GetAlive()) { SelectUnit(rayHitUnit, GameState.Roam); UpdateMoveablePreview(null); } } } } // Else hit the terrain, move the currently selected unit. else if (Physics.Raycast(m_MouseRay, out m_MouseWorldRayHit, Mathf.Infinity)) { if (m_SelectedUnit != null) { if (m_LeftMouseDown) { // Move the formation object to the position of the player's cursor in the world. m_GroupFormation.transform.position = m_MouseWorldRayHit.point; Vector3 meanPosition = Vector3.zero; // Go through all the player units. foreach (Unit u in UnitsManager.m_Instance.m_PlayerUnits) { meanPosition += u.transform.position; // Set all the units to move to their respective positions in the formation. switch (u.m_CharacterName) { case "Death": u.SetDestination(m_GroupFormation.GetDeathPosition().position); break; case "Pestilence": u.SetDestination(m_GroupFormation.GetPestilencePosition().position); break; case "Famine": u.SetDestination(m_GroupFormation.GetFaminePosition().position); break; case "War": u.SetDestination(m_GroupFormation.GetWarPosition().position); break; } } meanPosition /= UnitsManager.m_Instance.m_PlayerUnits.Count; // Rotate the formation object to look away from the characters. m_GroupFormation.transform.rotation = Quaternion.LookRotation(m_GroupFormation.transform.position - meanPosition); } } } Debug.DrawLine(m_MainCamera.transform.position, m_MouseWorldRayHit.point, Color.white, 0.0f); }