TeHArGiS10

Untitled

Jun 24th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. #pragma strict
  2.  
  3. var Player: GameObject;
  4. var mainCam: Camera;
  5. var jumpCount: float = 0;
  6. var playerSpeed: float = 0.8;
  7. var runSpeed: float = 1.0;
  8. var jumpForce: float = 10;
  9. var Sensitivity: float = 2;
  10.  
  11. function Start () {
  12. jumpCount = 0;
  13. playerSpeed = 0.8;
  14. jumpForce = 10;
  15. Sensitivity = 2;
  16. runSpeed = 1.0;
  17. }
  18.  
  19. function Update () {
  20. if(Input.GetKey(KeyCode.W)) {
  21. Player.GetComponent.<Rigidbody>().AddForce(transform.forward * playerSpeed, ForceMode.Impulse);
  22. }
  23. if(Input.GetKey(KeyCode.S)) {
  24. Player.GetComponent.<Rigidbody>().AddForce(-transform.forward * playerSpeed, ForceMode.Impulse);
  25. }
  26. if(Input.GetKey(KeyCode.A)) {
  27. Player.GetComponent.<Rigidbody>().AddForce(-transform.right * playerSpeed, ForceMode.Impulse);
  28. }
  29. if(Input.GetKey(KeyCode.D)) {
  30. Player.GetComponent.<Rigidbody>().AddForce(transform.right * playerSpeed, ForceMode.Impulse);
  31. }
  32. if(Input.GetKeyDown(KeyCode.Space) && jumpCount == 0) {
  33. Player.GetComponent.<Rigidbody>().AddForce(transform.up * jumpForce, ForceMode.Impulse);
  34. jumpCount = 1;
  35. }
  36. if(Input.GetKey(KeyCode.W) && (Input.GetKey(KeyCode.LeftShift))) {
  37. Player.GetComponent.<Rigidbody>().AddForce(transform.forward * runSpeed, ForceMode.Impulse);
  38. }
  39. if(Input.GetKey(KeyCode.S) && (Input.GetKey(KeyCode.LeftShift))) {
  40. Player.GetComponent.<Rigidbody>().AddForce(-transform.forward * runSpeed, ForceMode.Impulse);
  41. }
  42. if(Input.GetKey(KeyCode.A) && (Input.GetKey(KeyCode.LeftShift))) {
  43. Player.GetComponent.<Rigidbody>().AddForce(-transform.right * runSpeed, ForceMode.Impulse);
  44. }
  45. if(Input.GetKey(KeyCode.D) && (Input.GetKey(KeyCode.LeftShift))) {
  46. Player.GetComponent.<Rigidbody>().AddForce(transform.right * runSpeed, ForceMode.Impulse);
  47. }
  48.  
  49. var X = -Input.GetAxisRaw("Mouse X");
  50. X = -X;
  51. var _Rotation: Vector3 = new Vector3(0f, X, 0f) * Sensitivity;
  52. Player.GetComponent.<Rigidbody>().MoveRotation(GetComponent.<Rigidbody>().rotation * Quaternion.Euler(_Rotation));
  53.  
  54. var Y = Input.GetAxisRaw("Mouse Y");
  55. Y = -Y;
  56. var camRotation: Vector3 = new Vector3(Y, 0f, 0f) * Sensitivity;
  57. mainCam.transform.Rotate(camRotation);
  58. }
  59.  
  60. function OnCollisionEnter() {
  61. jumpCount = 0;
  62. }
Add Comment
Please, Sign In to add comment