示例#1
0
    // Update is called once per frame
    void Update()
    {
        float curX = gameObject.transform.position.x;

        move = Vector3.zero;
        if (currentState == State.Right)
        {
            if (curX < rightBound) // Still can move right
            {
                move += Vector3.right * moveSpeed;
            }
            else
            {
                currentState = State.Up;
            }
        }
        else if (currentState == State.Left)
        {
            if (curX > leftBound) // Still can move right
            {
                move += Vector3.left * moveSpeed;
            }
            else
            {
                currentState = State.Down;
            }
        }
        else if (currentState == State.Up)
        {
            if (currentFrameCount < upDownFrameCount)
            {
                move += Vector3.up * moveSpeed;
                ++currentFrameCount;
            }
            else
            {
                currentState      = State.Left;
                currentFrameCount = 0;
            }
        }
        else if (currentState == State.Down)
        {
            if (currentFrameCount < upDownFrameCount)
            {
                move += Vector3.down * moveSpeed;
                ++currentFrameCount;
            }
            else
            {
                currentState      = State.Right;
                currentFrameCount = 0;
            }
        }

        float speedMult = managerScript.GetEnemySpeedMult();

        if (speedMult < 0)
        {
            speedMult = 0;
        }
        transform.position += move * Time.deltaTime * speedMult;
    }