Advertisement
jemmm

Untitled

Sep 17th, 2019
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 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 float speed = 100f;
  8. Rigidbody rb;
  9. Vector3 v, r;
  10. // Start is called before the first frame update
  11. void Start()
  12. {
  13. rb = GetComponent<Rigidbody>();
  14. }
  15.  
  16. // Update is called once per frame
  17. void Update()
  18. {
  19. float x = 0, y = 0, z = 0, j = 0;
  20.  
  21. if (Input.GetKey(KeyCode.W))
  22. {
  23. z = 1;
  24. }
  25. if (Input.GetKey(KeyCode.S))
  26. {
  27. z = -1;
  28. }
  29. if (Input.GetKey(KeyCode.A))
  30. {
  31. y = -1;
  32. }
  33. if (Input.GetKey(KeyCode.D))
  34. {
  35. y = 1;
  36. }
  37. if (Input.GetKey(KeyCode.Space))
  38. {
  39. if (transform.position.y < 10)
  40. {
  41. j = 1;
  42. z += 10;
  43. }
  44. }
  45.  
  46.  
  47.  
  48. v = new Vector3(x, j, z) * speed;
  49.  
  50. r = new Vector3(0, y, 0) * 200;
  51.  
  52. rb.AddRelativeForce(v);
  53. rb.AddTorque(r);
  54.  
  55.  
  56. }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement