Euras

PlayerJump

Feb 1st, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.46 KB | None | 0 0
  1. void Update()
  2. {
  3.     int i = 0;
  4.     while (i < Input.touchCount)
  5.     {
  6.         if(Input.GetTouch(i).phase == TouchPhase.Began)
  7.         {
  8.             RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.GetTouch(i).position), -Vector2.up);
  9.             if(hit.collider.tag == "panel" && GroundCheck.isGrounded)
  10.             {
  11.                 jump = !jump;
  12.             }
  13.         }
  14.         ++i;
  15.     }
  16. }
  17.  
  18. void FixedUpdate()
  19. {
  20.     if(jump)
  21.     {
  22.         r.AddForce(Vector2.up * jumpSeed, ForceMode2D.Force);
  23.         jump = !jump;
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment