// Update is called once per frame
    void Update()
    {
        //if the player left clicks
        if (Input.GetMouseButtonDown(0))
        {
            //calculate whether anything has been clicked on
            Vector2      mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            RaycastHit2D hit      = Physics2D.Raycast(mousePos, Vector2.zero);

            //if an object containing a formation was clicked on, select it
            if (hit)
            {
                selectedFormation = hit.collider.GetComponent <Formation>();
                Debug.Log(selectedFormation.GetName());
            }
        }
        //if the player right clicks
        if (Input.GetMouseButtonDown(1))
        {
            //calculate whether anything has been clicked on
            Vector2      mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            RaycastHit2D hit      = Physics2D.Raycast(mousePos, Vector2.zero);
            Formation    temp     = null;

            if (hit)
            {
                temp = hit.collider.GetComponent <Formation>();
                //Debug.Log(selectedFormation.GetName());
            }

            //take an action based on the current phase
            switch (GameController.currentPhase)
            {
            case GameController.BattlePhase.MISSILE:
                if (temp != null)
                {
                    //add prompt or seperate controls for non-volley missile fire
                    selectedFormation.RangedAttack(temp, true);
                }
                break;

            case GameController.BattlePhase.MOVEMENT:
                StartCoroutine(selectedFormation.MoveToHex(mousePos));
                break;

            case GameController.BattlePhase.MELEE:
                if (temp != null)
                {
                    selectedFormation.MeleeAttack(temp);
                }
                break;
            }
        }
        //if hitting enter, change the phase
        if (Input.GetKeyDown(KeyCode.Return))
        {
            GameController.main.ChangePhase();
        }
        //turn to the right
        if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            if (selectedFormation != null)
            {
                //right arrow key turns the selectedformation to the right
                selectedFormation.ChangeFacing(1);
            }
        }
        //turn to the left
        if (Input.GetKeyDown(KeyCode.LeftArrow))
        {
            if (selectedFormation != null)
            {
                //right arrow key turns the selectedformation to the right
                selectedFormation.ChangeFacing(-1);
            }
        }
        //move forward one hex
        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            if (selectedFormation != null)
            {
                //get the grid and starting node
                PathGrid grid      = selectedFormation.GetPathGrid();
                PathNode startNode = grid.WorldToNode(selectedFormation.transform.position);
                //find the node in front of the formation and move to it
                foreach (PathNode node in grid.GetAdjacentNodes(startNode))
                {
                    if (node.facing == selectedFormation.GetFacing())
                    {
                        StartCoroutine(selectedFormation.MoveToHex(grid.NodeToWorld(node)));
                    }
                }
            }
        }
    }