void Update_UnitAttack()
    {
        // Click on enemy unit to set as TargetUnit
        if (tileUnderMouse != null && Input.GetMouseButtonUp(0))
        {
            Debug.Log("Mouse Up: Attack Click!");

            // could there be more than one unit on a tile?
            Unit[] us = tileUnderMouse.Units();

            if (us != null && us.Length > 0)
            {
                if (SelectedUnit != us[0])
                {
                    TargetUnit = us[0];
                }
            }
            else
            {
                Debug.Log("No target unit found");
                SelectedUnitState = SELECTED_UNIT_STATE.WAITING;
                SelectedUnit      = null;
                return;
            }

            Debug.Log(SelectedUnit.Name);
            Debug.Log(TargetUnit.Name);

            // TargetUnit has been set, display attacks menu
            SelectedUnitState = SELECTED_UNIT_STATE.ATTACK;
        }
    }
    // Update is called once per frame
    void Update()
    {
        tileUnderMouse = MouseToTile();

        HighlightTile();

        if (Input.GetKeyDown(KeyCode.Escape))
        {
            SelectedUnit      = null;
            TargetUnit        = null;
            SelectedUnitState = SELECTED_UNIT_STATE.WAITING;
            CancelUpdateFunc();
        }

        Update_CurrentFunc();

        Update_ScrollZoom();

        lastMousePosition  = Input.mousePosition;
        tileLastUnderMouse = tileUnderMouse;

        if (SelectedUnit != null)
        {
            // draw the path
            DrawPath((tilePath != null) ? tilePath : SelectedUnit.GetTilePath());
            // show/hide correct unit selection panels
            switch (SelectedUnitState)
            {
            case SELECTED_UNIT_STATE.MOVE:
                UnitActionPanel.SetActive(true);
                UnitAttackPanel.SetActive(false);
                UnitItemPanel.SetActive(false);
                break;

            case SELECTED_UNIT_STATE.ATTACK:
                UnitActionPanel.SetActive(false);
                UnitAttackPanel.SetActive(true);
                UnitItemPanel.SetActive(false);
                break;

            case SELECTED_UNIT_STATE.ITEM:
                UnitActionPanel.SetActive(false);
                UnitAttackPanel.SetActive(false);
                UnitItemPanel.SetActive(true);
                break;

            case SELECTED_UNIT_STATE.WAITING:
                UnitActionPanel.SetActive(true);
                UnitAttackPanel.SetActive(false);
                UnitItemPanel.SetActive(false);
                break;
            }
        }
        else
        {
            DrawPath(null);
        }
    }
    void Update_DetectModeStart()
    {
        // If we are over a UI element ignore mouse clicks
        if (EventSystem.current.IsPointerOverGameObject())
        {
            return;
        }

        if (Input.GetMouseButtonDown(0))
        {
            // LMB just went down
            //Debug.Log("Mouse Down");
        }
        else if (Input.GetMouseButtonUp(0))
        {
            //Debug.Log("Mouse Up: Click!");

            // could there be more than one unit on a tile?
            Unit[] us = tileUnderMouse.Units();

            if (us != null && us.Length > 0)
            {
                if (SelectedUnit != us[0])
                {
                    SelectedUnitState = SELECTED_UNIT_STATE.WAITING;
                }
                SelectedUnit = us[0];
            }
            else
            {
                Debug.Log("No selected unit found");
                SelectedUnitState = SELECTED_UNIT_STATE.WAITING;
                SelectedUnit      = null;
                return;
            }
        }
        else if (SelectedUnit != null && SelectedUnitState == SELECTED_UNIT_STATE.MOVE)
        {
            // selected a unit and right mouse button is down
            Update_CurrentFunc = Update_UnitMovement;
        }
        else if (Input.GetMouseButton(0) && Vector3.Distance(Input.mousePosition, lastMousePosition) > mouseDragThreshold)
        {
            // LMB held down AND the mouse moved.  Drag the camera
            Update_CurrentFunc           = Update_CameraDrag;
            lastMouseGroundPlanePosition = MouseToGroundPlane(Input.mousePosition);
            Update_CurrentFunc();
        }
    }
 public void CancelButton()
 {
     SelectedUnitState = SELECTED_UNIT_STATE.WAITING;
     CancelUpdateFunc();
 }
 public void ItemButton()
 {
     SelectedUnitState = SELECTED_UNIT_STATE.ITEM;
     // replace with function call that deals with items
     CancelUpdateFunc();
 }
 public void MoveButton()
 {
     SelectedUnitState = SELECTED_UNIT_STATE.MOVE;
 }