Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 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.     void FixedUpdate ()
  35.     {
  36.         float hor = Input.GetAxis ("Horizontal");
  37.         rb.velocity = new Vector2(hor * speed,rb.velocity.y);
  38.  
  39.  
  40.         isGrounded = Physics2D.OverlapCircle (groundCheck.position, 0.15f, whatIsGround);
  41.  
  42.         if (jump) {
  43.  
  44.             rb.AddForce (new Vector2(0, jumpForce));
  45.             jump = false;
  46.  
  47.         }
  48.         if (doubleJump && Input.GetButtonDown("Jump")) {
  49.             rb.AddForce (new Vector2(0, doubleJumpForce));
  50.             doubleJump = false;
  51.        
  52.         }
  53.         }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement