Advertisement
Guest User

qq

a guest
Sep 25th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerMovement : MonoBehaviour
  6. {
  7.  
  8. public float speed = 3.0f;
  9. public float rotSpeed = 150.0f;
  10. private bool isSprinting;
  11. public Rigidbody rb;
  12. private bool canJump;
  13. private bool isJumping;
  14.  
  15. // Update is called once per frame
  16. void Update()
  17. {
  18. var x = Input.GetAxis("Horizontal") * Time.deltaTime * rotSpeed;
  19. var z = Input.GetAxis("Vertical") * Time.deltaTime * speed;
  20.  
  21. transform.Rotate(0, x, 0);
  22. transform.Translate(0, 0, z);
  23. //poruszanie sie
  24.  
  25. if (Input.GetKeyDown(KeyCode.LeftShift))
  26. {
  27. speed = 5.0f;
  28. isSprinting = true;
  29. }
  30. if (Input.GetKeyUp(KeyCode.LeftShift))
  31. {
  32. speed = 3.0f;
  33. isSprinting = false;
  34. }
  35. //sprint
  36.  
  37. if (Input.GetKeyDown(KeyCode.Space))
  38. {
  39. if (canJump == true)
  40. {
  41. rb.AddForce(0, 10000 * Time.deltaTime, 0);
  42. }
  43. else if(Input.GetKeyDown(KeyCode.Space) && isJumping)
  44. {
  45.  
  46. }
  47.  
  48. }
  49. }
  50.  
  51. private void OnCollisionEnter(Collision collision)
  52. {
  53. if(collision.gameObject.tag == "ground")
  54. {
  55. canJump = true;
  56. Debug.Log("moge skakac");
  57. }
  58.  
  59. }
  60. private void OnCollisionExit(Collision collision)
  61. {
  62. if (collision.gameObject.tag == "ground")
  63. {
  64. canJump = false;
  65. isJumping = true;
  66. Debug.Log("nie moge skakac bo skoczylem se wlasnie xD");
  67.  
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement