コード例 #1
0
ファイル: BoxAction.cs プロジェクト: sveigmic/Bad_Dream
 public override bool HandleInput()
 {
     if (joystick.IsThereInput() && grounder.IsGrounded())
     {
         float y = joystick.Input.y;
         float x = joystick.Input.x / Mathf.Abs(joystick.Input.x);
         //y = (y < 0) ? y*attrs.pushSpeed : -5f + rb.velocity.y;
         rb.velocity = new Vector2(x * attrs.pushSpeed, rb.velocity.y);
     }
     if (Input.GetKeyDown(KeyCode.O))
     {
         StopHolding();
         return(false);
     }
     return(true);
 }
コード例 #2
0
ファイル: MoveState.cs プロジェクト: Usatej/BadDream
    public override void HandleInput()
    {
        //Movement Horizontal
        if (joystick.IsThereInput() && player.grounder.IsGrounded())
        {
            float x = joystick.Input.x;

            if (player.grounder.IsOnMovingObject())
            {
                Vector2 tmp = player.grounder.MovingObjectVelocity();
                rb.velocity = new Vector2(attr.moveSpeed * x + tmp.x, rb.velocity.y);
            }
            else
            {
                rb.velocity = new Vector2(attr.moveSpeed * x, rb.velocity.y);
            }

            if (x > 0)
            {
                player.transform.localScale = new Vector3(1, 1, 1);
            }
            else if (x < 0)
            {
                player.transform.localScale = new Vector3(-1, 1, 1);
            }
            anim.SetFloat("speed", Mathf.Abs(x));
        }
        else
        {
            anim.SetFloat("speed", 0);
        }

        //Jumping
        if ((touchManager.AreaSwipeUp || Input.GetKeyDown(KeyCode.Space)))
        {
            if (player.grounder.IsGrounded())
            {
                rb.velocity = new Vector2(rb.velocity.x, player.attributes.jumpForce);
                player.actualPhase.SendRequestToCreateState(PlayerStates.Air);
            }
        }

        if ((touchManager.AreaSwipeDown || Input.GetKeyDown(KeyCode.S)))
        {
            if (player.grounder.IsGrounded())
            {
                rb.velocity = new Vector2(rb.velocity.x, player.attributes.jumpForce);
                player.actualPhase.SendRequestToCreateState(PlayerStates.Air);
            }
        }
    }