示例#1
0
    // Update is called once per frame
    void Update()
    {
        if (gameObject.tag == "Selected")
        {
            //move right
            if (Input.GetKeyDown(KeyCode.RightArrow))
            {
                Command move = new MoveObject(gameObject, new Vector3(1, 0, 0));

                move.Execute();
                CommandManager.Instance().addcommand(move);
            }


            //move left
            if (Input.GetKeyDown(KeyCode.LeftArrow))
            {
                Command move = new MoveObject(gameObject, new Vector3(-1, 0, 0));

                move.Execute();
                CommandManager.Instance().addcommand(move);
            }
            //move backwards
            if (Input.GetKeyDown(KeyCode.DownArrow))
            {
                Command move = new MoveObject(gameObject, new Vector3(0, 0, -1));
                move.Execute();
                CommandManager.Instance().addcommand(move);
            }
            //move forwards
            if (Input.GetKeyDown(KeyCode.UpArrow))
            {
                Command move = new MoveObject(gameObject, new Vector3(0, 0, 1));
                move.Execute();
                CommandManager.Instance().addcommand(move);
            }

            //move up
            if (Input.GetKeyDown(KeyCode.PageUp))
            {
                Command move = new MoveObject(gameObject, new Vector3(0, 1, 0));
                move.Execute();
                CommandManager.Instance().addcommand(move);
            }
            //move down
            if (Input.GetKeyDown(KeyCode.PageDown))
            {
                Command move = new MoveObject(gameObject, new Vector3(0, -1, 0));

                move.Execute();
                CommandManager.Instance().addcommand(move);
            }

            ////rotate
            //rotate left
            if (Input.GetKeyDown(KeyCode.C))
            {
                Command rotate = new RotateObject(gameObject, new Vector3(0, -90, 0));

                rotate.Execute();
                CommandManager.Instance().addcommand(rotate);
            }

            //rotate right
            if (Input.GetKeyDown(KeyCode.V))
            {
                Command rotate = new RotateObject(gameObject, new Vector3(0, 90, 0));
                rotate.Execute();
                CommandManager.Instance().addcommand(rotate);
            }

            //rotate up
            if (Input.GetKeyDown(KeyCode.B))
            {
                Command rotate = new RotateObject(gameObject, new Vector3(-90, 0, 0));
                rotate.Execute();
                CommandManager.Instance().addcommand(rotate);
            }

            //rotate down
            if (Input.GetKeyDown(KeyCode.N))
            {
                Command rotate = new RotateObject(gameObject, new Vector3(90, 0, 0));
                rotate.Execute();
                CommandManager.Instance().addcommand(rotate);
            }
        }
    }