Kenkaster001

Player

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