Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class controller : MonoBehaviour
  6. {
  7. private float MovementInput;
  8. public byte movementspeed;
  9.  
  10. public float jumpforce;
  11.  
  12. private Rigidbody2D rb;
  13.  
  14. private BoxCollider2D col;
  15.  
  16. private float zero;
  17.  
  18. private float Pos;
  19.  
  20. private float PPos;
  21.  
  22. private float xrespawn;
  23.  
  24. private float yrespawn;
  25.  
  26. void Start()
  27. {
  28. movementspeed = 20;
  29. jumpforce = 20f;
  30.  
  31. rb = GetComponent<Rigidbody2D>();
  32. col = GetComponent<BoxCollider2D>();
  33.  
  34. Pos = rb.position.y;
  35. PPos = 0;
  36.  
  37. xrespawn = 0.28f;
  38. yrespawn = 2.93f;
  39. }
  40.  
  41. void Update()
  42. {
  43. Pos = rb.position.y;
  44.  
  45. MovementInput = Input.GetAxisRaw("Horizontal");
  46.  
  47. PPos = Pos;
  48. }
  49.  
  50. void FixedUpdate()
  51. {
  52.  
  53.  
  54.  
  55. Debug.Log(Mathf.Round(Pos));
  56.  
  57. Debug.Log("And");
  58.  
  59. Debug.Log(Mathf.Round(PPos));
  60.  
  61. //if (Input.GetKeyDown(KeyCode.Space) && (Mathf.Round(Pos*10) == Mathf.Round(PPos*10)))
  62. if (Input.GetKeyDown(KeyCode.Space))
  63. {
  64. rb.velocity = Vector2.up * jumpforce;
  65. }
  66.  
  67.  
  68. rb.velocity = new Vector2(MovementInput * movementspeed, rb.velocity.y - 1);
  69.  
  70.  
  71. if (Pos < -20f)
  72. {
  73. rb.position = new Vector2(xrespawn , yrespawn);
  74. }
  75.  
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement