Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.35 KB | None | 0 0
  1. using System.Collections;
  2.  
  3. public class movementRigibody : MonoBehaviour {
  4.  
  5.     public float speed = 20;
  6.     public float jumpForce= 550f;
  7.     public float doubleJumpForce = 500f;
  8.     public Transform groundCheck;
  9.     public LayerMask whatIsGround;
  10.     bool doubleJump = false;
  11.  
  12.  
  13.     private Rigidbody2D rb;
  14.     private bool isGrounded = false;
  15.     private bool jump = false;
  16.     private bool canDoubleJump = false;
  17.  
  18.     void Start ()
  19.     {
  20.         rb = GetComponent<Rigidbody2D>();
  21.     }
  22.     void Update (){
  23.         if (Input.GetButtonDown("Jump") {
  24.             if (isGrounded) {
  25.                 jump = true;
  26.                 canDoubleJump = true;
  27.             } else if (canDoubleJump) {
  28.                 doubleJump = true;
  29.                 canDoubleJump = false;
  30.             }
  31.         }
  32.  
  33.     }
  34.  
  35.     void FixedUpdate ()
  36.     {
  37.         float hor = Input.GetAxis ("Horizontal");
  38.         rb.velocity = new Vector2(hor * speed,rb.velocity.y);
  39.  
  40.  
  41.         isGrounded = Physics2D.OverlapCircle (groundCheck.position, 0.15f, whatIsGround);
  42.  
  43.         if (jump) {
  44.  
  45.             rb.AddForce (new Vector2(0, jumpForce));
  46.             jump = false;
  47.  
  48.         }
  49.         if (doubleJump && Input.GetButtonDown("Jump")) {
  50.             rb.AddForce (new Vector2(0, doubleJumpForce));
  51.             doubleJump = false;
  52.        
  53.         }
  54.         }
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement