Exemple #1
0
    public void Execute(Player player)
    {
        if (Input.GetKey(KeyCode.LeftShift))
        {
            // transition to ducking
            DuckingPlayerState duckingState = new DuckingPlayerState();
            duckingState.Enter(player);
        }

        if (Input.GetKey(KeyCode.W))
        {
            MoveForwardPlayerState movingForward = new MoveForwardPlayerState();
            movingForward.Enter(player);
        }

        if (Input.GetKey(KeyCode.S))
        {
            MoveBackwardsPlayerState movingBackwards = new MoveBackwardsPlayerState();
            movingBackwards.Enter(player);
        }

        if (Input.GetKey(KeyCode.D))
        {
            MoveRightPlayerState movingRight = new MoveRightPlayerState();
            movingRight.Enter(player);
        }

        if (Input.GetKey(KeyCode.A))
        {
            MoveLeftPlayerState movingLeft = new MoveLeftPlayerState();
            movingLeft.Enter(player);
        }

        if (Input.GetKey(KeyCode.Space) && player.onGround == true)
        {
            //player.onGround = false;
            JumpingPlayerState jumpingState = new JumpingPlayerState();
            jumpingState.Enter(player);
        }
    }
Exemple #2
0
    public void Execute(Player player)
    {
        Rigidbody rbPlayer = player.GetComponent <Rigidbody>();

        rbPlayer.AddForce(10, 0, 10);

        if (!Input.GetKey(KeyCode.D) && Input.GetKey(KeyCode.W))
        {
            MoveForwardPlayerState movingForward = new MoveForwardPlayerState();
            movingForward.Enter(player);
        }

        if (!Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.D))
        {
            MoveRightPlayerState movingRight = new MoveRightPlayerState();
            movingRight.Enter(player);
        }

        if (!Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.D))
        {
            StandingPlayerState standingState = new StandingPlayerState();
            standingState.Enter(player);
        }

        if (Input.GetKey(KeyCode.LeftShift))
        {
            // transition to ducking
            DuckingPlayerState duckingState = new DuckingPlayerState();
            duckingState.Enter(player);
        }

        if (Input.GetKey(KeyCode.Space) && player.onGround == true)
        {
            JumpingPlayerState jumpingState = new JumpingPlayerState();
            jumpingState.Enter(player);
        }
    }