Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerController : MonoBehaviour
  6. {
  7. public float speed;
  8. public float JumpForce;
  9. private float moveInput;
  10.  
  11. private Rigidbody2D rb;
  12.  
  13. private bool isGrounded;
  14. public Transform groundCheck;
  15. public float checkRadius;
  16. public LayerMask whatisGround;
  17.  
  18. // Use this for initialization
  19. void Start () {
  20. extraJumps = extraJumpvalie;
  21. rb = GetComponent<Rigidbody2D>();
  22. }
  23.  
  24. private void FixedUpdate()
  25. {
  26. isGrounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatisGround);
  27.  
  28. moveInput = Input.GetAxis("Horizontal");
  29. rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
  30. }
  31.  
  32. // Update is called once per frame
  33. void Update ()
  34. {
  35. if(isGrounded == true){
  36. extraJumps = extraJumpvalue;
  37. }
  38. if (Input.GetKeyDown(KeyCode.Space) && extraJumps > 0)
  39. {
  40. rb.velocity = new Vector2(rb.velocity.x, jumpForce);
  41. extraJumps;
  42. } else if(Input.GetKeyDown(KeyCode.Space) && extraJumps == 0)
  43. {
  44. RenderBuffer.velocity = Vector2.up * jumpForce;
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement