Advertisement
Guest User

Untitled

a guest
May 26th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. PlayerController.cs
  2.  
  3. using UnityEngine;
  4. using System.Collections;
  5.  
  6. [System.Serializable]
  7. public class Boundary
  8. {
  9. public float xMin, xMax, zMin, zMax;
  10.  
  11.  
  12. }
  13.  
  14.  
  15. public class PlayerController : MonoBehaviour {
  16.  
  17.  
  18. public float speed;
  19. public Boundary boundary;
  20. public float tilt;
  21.  
  22. // Use this for initialization
  23. void FixedUpdate()
  24. {
  25. float moveHorizontal = Input.GetAxis("Horizontal");
  26. float moveVertical = Input.GetAxis("Vertical");
  27.  
  28. Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
  29.  
  30. GetComponent<Rigidbody>().velocity = movement * speed;
  31.  
  32. GetComponent<Rigidbody>().position = new Vector3(
  33. Mathf.Clamp(GetComponent<Rigidbody>().position.x,boundary.xMin, boundary.xMax),
  34. 0.0f,
  35. Mathf.Clamp(GetComponent<Rigidbody>().position.z, boundary.zMin, boundary.zMax));
  36.  
  37.  
  38. GetComponent<Rigidbody>().rotation = Quaternion.Euler(0,0, GetComponent<Rigidbody>().velocity.x * -tilt);
  39. }
  40. }
  41.  
  42. float moveHorizontal = Input.GetAxis("Horizontal");
  43. float moveVertical = Input.GetAxis("Vertical");
  44.  
  45. float moveHorizontal = Input.GetAxis("Horizontal");
  46. float moveVertical = Input.GetAxis("Vertical");
  47. Debug.Log("Movement: " + moveHorizontal + ", " + moveVertical); // <-- add this
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement