Guest User

Untitled

a guest
Jun 2nd, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Player : MonoBehaviour {
  6.  
  7. [SerializeField]
  8. private float movementSpeed = 0.0f;
  9. public Rigidbody rb;
  10.  
  11. void Start ()
  12. {
  13. Physics.gravity = new Vector3 (0, -45F, 0);
  14. rb = GetComponent<Rigidbody> ();
  15. }
  16.  
  17. void Update ()
  18. {
  19. Move ();
  20. }
  21.  
  22. private void Move ()
  23. {
  24.  
  25. if (Input.GetAxis ("Vertical") != 0)
  26. {
  27. rb.constraints = RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationX;
  28. float hAxis = Input.GetAxis ("Vertical");
  29. Vector3 moveDir = new Vector3 (hAxis, 0, 0);
  30. rb.velocity = moveDir * movementSpeed * Time.deltaTime;
  31. }
  32. else if (Input.GetAxis ("Horizontal") != 0)
  33. {
  34. rb.constraints = RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ;
  35. float hAxis = Input.GetAxis("Horizontal");
  36. Vector3 moveDir = new Vector3 (0, 0, hAxis);
  37. rb.velocity = moveDir * movementSpeed * Time.deltaTime;
  38. }
  39.  
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment