Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        if (playerState.IsEnabled())
        {
            float moveSpeed = maxMoveSpeed;
            if (slowed)
            {
                moveSpeed /= 2;
            }
            playerJump = this.GetComponentInChildren <PlayerJump>();
            Vector3 newVelocity = rigid.velocity;

            //Horizontal
            float vel = Input.GetAxis("Horizontal") * moveSpeed;
            if (Mathf.RoundToInt(vel) != 0)
            {
                newVelocity.x += vel;
                if (vel > 0 && newVelocity.x > moveSpeed)
                {
                    newVelocity.x = moveSpeed;
                }
                else if (vel < 0 && newVelocity.x < -1 * moveSpeed)
                {
                    newVelocity.x = -moveSpeed;
                }
                rigid.velocity = newVelocity;
            }
            else if ((playerJump.IsGrounded() && !playerState.IsFlying()) || (!playerJump.IsGrounded() && playerJump.IsStillJumped()))
            {
                rigid.velocity = new Vector3(0, rigid.velocity.y);
            }
        }
    }
Exemple #2
0
    // Update is called once per frame
    void LateUpdate()
    {
        if (playerState.IsShooting())
        {
            timeSinceLastShot = 0f;
        }
        else
        {
            timeSinceLastShot += Time.deltaTime;
        }
        if (playerState.IsStanding()) //Standing Form
        {
            morphed = false;
            if (playerJump.IsGrounded()) //On Ground
            {
                shotInAir = false;
                spinMove  = false;
                running   = playerState.IsRunning();
                if (playerDirection.IsHoldingUp()) //Is holding up key
                {
                    playerState.SetLookingUp(true);
                }
                else //isnt holding up key
                {
                    playerState.SetLookingUp(false);
                }
            }
            else //In Air
            {
                running = false;
                if (playerState.IsShooting()) //is shooting
                {
                    shotInAir = true;
                }
                if (shotInAir)
                {
                    if (playerDirection.IsHoldingUp()) //is holding up key
                    {
                        playerState.SetLookingUp(true);
                        if (playerState.IsMissleOn())
                        {
                            spriteRenderer.sprite = missleJumpShootUp;
                        }
                        else
                        {
                            spriteRenderer.sprite = jumpShootUp;
                        }
                    }
                    else //isnt holding up key
                    {
                        playerState.SetLookingUp(false);

                        if (playerState.IsMissleOn())
                        {
                            spriteRenderer.sprite = missleJumpShootRight;
                        }
                        else
                        {
                            spriteRenderer.sprite = jumpShootRight;
                        }
                    }
                    spinMove = false;
                }
                else if (playerJump.IsStillJumped()) //jumped from stationary
                {
                    if (playerState.IsMissleOn())
                    {
                        spriteRenderer.sprite = missleStillJumpRight;
                    }
                    else
                    {
                        spriteRenderer.sprite = stillJumpRight;
                    }

                    spinMove = false;
                }
                else if (playerJump.IsMoveJumped()) //is beyblade
                {
                    spinMove = true;
                }
            }
        }
        else //morph ball
        {
            morphed = true;
        }
    }