Advertisement
Guest User

Untitled

a guest
May 14th, 2019
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class PlayerController : MonoBehaviour
  4. {
  5. public CharacterController cc;
  6. public float Speed;
  7. public float JumpHeight;
  8.  
  9. Vector3 move;
  10.  
  11. private void Start()
  12. {
  13. cc = GetComponent<CharacterController>();
  14. }
  15.  
  16. private void Update()
  17. {
  18. float y = move.y;
  19. move = new Vector3(Input.GetAxisRaw("Horizontal"), 0, 0) * Speed;
  20. move.y = y;
  21.  
  22. if (cc.isGrounded)
  23. {
  24. move.y = 0;
  25. if (Input.GetButtonDown("Jump"))
  26. {
  27. move.y = JumpHeight;
  28. }
  29. }
  30.  
  31. move.y = move.y + (Physics.gravity.y * 1f * Time.deltaTime);
  32. cc.Move(move * Time.deltaTime);
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement