Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class PlayerController : MonoBehaviour
  5. {
  6. private Rigidbody rigidbody;
  7.  
  8. void Start()
  9. {
  10. rigidbody = gameObject.GetComponent<Rigidbody>();
  11. }
  12.  
  13. public float speed;
  14.  
  15. void FixedUpdate()
  16. {
  17. float moveHorizontal = Input.GetAxis ("Horizontal");
  18. float moveVertical = Input.GetAxis ("Vertical");
  19.  
  20. Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
  21. rigidbody.velocity = movement * speed;
  22.  
  23. rigidbody.position = new Vector3
  24. (
  25. Mathf.Clamp (rigidbody.position.x, xMin, xMax),
  26. 0.0f,
  27. Mathf.Clamp (rigidbody.position.z, zMin, zMax)
  28. );
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement