Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Player : MonoBehaviour
  6. {
  7. Rigidbody rb;
  8. public float s = 50f;
  9. public float rs = 200f;
  10. Vector3 v, r;
  11. public float j = 0f;
  12. // Start is called before the first frame update
  13. void Start()
  14. {
  15. rb = GetComponent<Rigidbody>();
  16. }
  17.  
  18. // Update is called once per frame
  19. void Update()
  20. {
  21. float x = 0, y = 0, z = 0;
  22. float j = 0;
  23. if (Input.GetKey(KeyCode.W))
  24. {
  25. z = 1;
  26. }
  27. if (Input.GetKey(KeyCode.S))
  28. {
  29. z = -1;
  30. }
  31. if (Input.GetKey(KeyCode.D))
  32. {
  33. y = 1;
  34. }
  35. if (Input.GetKey(KeyCode.A))
  36. {
  37. y = -1;
  38. }
  39. if (Input.GetKey(KeyCode.Space))
  40. {
  41. if (transform.position.y <= 0.55)
  42. {
  43. j = 20;
  44. z += 1;
  45.  
  46. }
  47. }
  48.  
  49. v = new Vector3(x, j, z) * s;
  50. r = new Vector3(0, y, 0) * rs;
  51.  
  52.  
  53.  
  54. }
  55. private void FixedUpdate()
  56. {
  57. rb.AddTorque(r);
  58. rb.AddRelativeForce(v);
  59.  
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement