コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        ClearAllLights();
        LightDirection();

        bool isPlayerTurn = scrGM.GetIsPlayerTurn();

        if (isPlayerTurn == false)
        {
            float step = moveSpeed * Time.deltaTime;

            gameObject.transform.position = Vector3.MoveTowards(gameObject.transform.position, goalPos, step);

            if (moveCurrent == 0 && gameObject.transform.position == goalPos)
            {
                scrGM.SetIsPlayerTurn(true);
                moveCurrent = moveMax;
            }

            if (gameObject.transform.position == goalPos && isGoing == true && pathNumber < path.Length - 1)
            {
                pathNumber++;
                goalPos = path[pathNumber];
                moveCurrent--;

                if (pathNumber == path.Length - 1)
                {
                    isGoing = false;
                }
            }
            else if (gameObject.transform.position == goalPos && isGoing == false && pathNumber > 0)
            {
                pathNumber--;
                goalPos = path[pathNumber];
                moveCurrent--;

                if (pathNumber == 0)
                {
                    isGoing = true;
                }
            }
        }
    }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        bool isPlayerTurn = scrGM.GetIsPlayerTurn();

        if (isPlayerTurn == true)
        {
            float step = moveSpeed * Time.deltaTime;

            gameObject.transform.position = Vector3.MoveTowards(gameObject.transform.position, goalPos, step);

            if (moveCurrent > 0)
            {
                if (canPressButton == true)
                {
                    if (isItFirstAppearance == true)
                    {
                        CheckMoveDirectionAllowed();
                        isItFirstAppearance = false;
                    }

                    if (Input.GetKeyDown("up") && isMoveUpAllowed == true)
                    {
                        goalPos        = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y + 1, gameObject.transform.position.z);
                        canPressButton = false;
                        moveCurrent--;
                        ClearArrows();
                    }
                    else if (Input.GetKeyDown("down") && isMoveDownAllowed == true)
                    {
                        goalPos        = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y - 1, gameObject.transform.position.z);
                        canPressButton = false;
                        moveCurrent--;
                        ClearArrows();
                    }
                    else if (Input.GetKeyDown("left") && isMoveLeftAllowed == true)
                    {
                        goalPos        = new Vector3(gameObject.transform.position.x - 1, gameObject.transform.position.y, gameObject.transform.position.z);
                        canPressButton = false;
                        moveCurrent--;
                        ClearArrows();
                    }
                    else if (Input.GetKeyDown("right") && isMoveRightAllowed == true)
                    {
                        goalPos        = new Vector3(gameObject.transform.position.x + 1, gameObject.transform.position.y, gameObject.transform.position.z);
                        canPressButton = false;
                        moveCurrent--;
                        ClearArrows();
                    }
                }

                if (gameObject.transform.position == goalPos)
                {
                    CheckMoveDirectionAllowed();
                    canPressButton = true;
                }
            }
            else if (moveCurrent == 0 && gameObject.transform.position == goalPos)
            {
                scrGM.SetIsPlayerTurn(false);
                moveCurrent = moveMax;
            }
        }
    }