Exemplo n.º 1
0
    void HorizontalMove()
    {
        float horizontalmove = Input.GetAxisRaw(gameObject.GetComponent <Controls>().horizontalMove);

        animator.SetFloat("speed", Mathf.Abs(horizontalmove));

        if (horizontalmove > 0 && canWalk && LevelManager.canMove)
        {
            if (direction == PlayerDirectionEnum.LEFT)
            {
                flip();
            }

            direction = PlayerDirectionEnum.RIGHT;
            gameObject.transform.Translate(horizontalSpeed * Time.deltaTime, 0, 0);
        }

        if (horizontalmove < 0 && canWalk)
        {
            if (PlayerDirectionEnum.RIGHT == direction)
            {
                flip();
            }
            direction = PlayerDirectionEnum.LEFT;
            gameObject.transform.Translate(-horizontalSpeed * Time.deltaTime, 0, 0);
        }
    }
Exemplo n.º 2
0
    void Jump()
    {
        float jump = Input.GetAxisRaw(gameObject.GetComponent <Controls>().verticalMove);

        if (jump > 0 && canJump && LevelManager.canMove)
        {
            animator.Play("Jump");
            directionTop = PlayerDirectionEnum.UP;

            rigidBody.velocity = new Vector2(rigidBody.velocity.x, 0);
            rigidBody.AddForce(new Vector2(0, jumpForce));
            canJump = false;
        }
        if (Input.GetAxisRaw(gameObject.GetComponent <Controls>().verticalMove) < 0)
        {
            directionTop = PlayerDirectionEnum.DOWN;
        }
    }
Exemplo n.º 3
0
    void HandleDirection()
    {
        float horizontal = Input.GetAxisRaw(gameObject.GetComponent <Controls>().horizontalMove);
        float vertical   = Input.GetAxisRaw(gameObject.GetComponent <Controls>().verticalMove);

        if (horizontal > 0)
        {
            direction = PlayerDirectionEnum.RIGHT;
        }
        if (horizontal < 0)
        {
            direction = PlayerDirectionEnum.LEFT;
        }
        if (vertical > 0)
        {
            direction = PlayerDirectionEnum.UP;
        }
        if (vertical < 0)
        {
            direction = PlayerDirectionEnum.DOWN;
        }
    }
Exemplo n.º 4
0
 public void CastDirection(PlayerDirectionEnum castDirection)
 {
     direction        = castDirection;
     positionOriginal = castDirection;
 }