Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class UnityMover : MonoBehaviour
  5. {
  6. public float Speed = 6f;
  7. public float JumpForce = 8f;
  8. public float Gravity = 9.83f;
  9. CharacterController controller;
  10.  
  11. void Awake()
  12. {
  13. controller = GetComponent<CharacterController>();
  14. }
  15. void Update()
  16. {
  17. Vector3 moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0f, Input.GetAxis("Vertical"));
  18. moveDirection = transform.TransformDirection(moveDirection);
  19. moveDirection *= Speed;
  20. if(Input.GetButton("Jump") && controller.isGrounded)
  21. {
  22. moveDirection.y = JumpForce;
  23. }
  24. moveDirection.y -= Gravity * Time.deltaTime;
  25. controller.Move(moveDirection * Time.deltaTime);
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement