matriga

Untitled

Dec 12th, 2025
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.08 KB | Gaming | 0 0
  1. public void EnableMovementAndJump(bool enable)
  2. {
  3.     canMove = enable;
  4.     canJump = enable;
  5. }
  6.  
  7. private void HandleAnimations()
  8. {
  9.     anim.SetFloat("xVelocity", rb.linearVelocity.x);
  10.     anim.SetFloat("yVelocity", rb.linearVelocity.y);
  11.     anim.SetBool("isGrounded", isGrounded);
  12. }
  13.  
  14. private void HandleInput()
  15. {
  16.     xInput = Input.GetAxisRaw("Horizontal");
  17.  
  18.     if (Input.GetKeyDown(KeyCode.Space))
  19.         TryToJump();
  20.  
  21.     if (Input.GetKeyDown(KeyCode.Mouse0))
  22.         TryToAttack();
  23.    
  24. }
  25.  
  26. private void TryToAttack()
  27. {
  28.     if (isGrounded)
  29.     {
  30.     anim.SetTrigger("attack");
  31.     rb.linearVelocity = new Vector2(0, rb.linearVelocity.y);
  32.     }
  33. }
  34.  
  35.  
  36. private void TryToJump()
  37. {
  38.     if (isGrounded && canJump)
  39.         rb.linearVelocity = new Vector2(rb.linearVelocity.x, jumpForce);
  40. }
  41.  
  42. private void HandleMovement()
  43. {
  44.     if(canMove)
  45.     rb.linearVelocity = new Vector2(xInput * moveSpeed, rb.linearVelocity.y);
  46. }
  47.  
  48. private void HandleCollision()
  49. {
  50.     isGrounded = Physics2D.Raycast(transform.position, Vector2.down, groundCheckDistance, whatIsGround);
  51. }
Advertisement
Add Comment
Please, Sign In to add comment