Пример #1
0
    void moveCursor()
    {
        if (Input.GetKeyDown(KeyCode.A))
        {
            cursor.transform.Translate(-1f, 0, 0);
            updateCursorColor();
        }

        if (Input.GetKeyDown(KeyCode.D))
        {
            cursor.transform.Translate(1f, 0, 0);
            updateCursorColor();
        }

        if (Input.GetKeyDown(KeyCode.W))
        {
            cursor.transform.Translate(0, 1f, 0);
            updateCursorColor();
        }

        if (Input.GetKeyDown(KeyCode.S))
        {
            cursor.transform.Translate(0, -1f, 0);
            updateCursorColor();
        }

        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (unitActionSelected)
            {
                unitActionSelected = false;
                //mc.removeZone ();
            }
            openMenu = false;
            changeCursorColor(MyColor.cyan);
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            if (!unitMenu && !unitActionSelected && !generalActionSelected)
            {
                openMenuOnSelection();
            }

            else if (unitActionSelected)
            {
                Vector3 tpos = cursor.transform.position;
                switch (actionOption)
                {
                case 0:
                    if (tms.canAttackTo(selectedGO, (int)tpos.z, (int)tpos.x))
                    {
                        tms.attackTo(selectedGO, (int)tpos.z, (int)tpos.x);
                        changeCursorColor(MyColor.cyan);
                    }
                    else
                    {
                        changeCursorColor(MyColor.red);
                    }
                    break;

                case 1:
                    if (tms.canMoveTo(selectedGO, (int)tpos.z, (int)tpos.x))
                    {
                        tms.moveTo(selectedGO, (int)tpos.z, (int)tpos.x);
                        changeCursorColor(MyColor.cyan);
                    }
                    else
                    {
                        changeCursorColor(MyColor.red);
                    }
                    break;

                default:
                    break;
                }

                unitActionSelected = false;
                //mc.removeZone ();
                selectedGO   = null;
                actionOption = -1;
            }
        }
    }