Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PlayerController.cs
- using UnityEngine;
- using System.Collections;
- [System.Serializable]
- public class Boundary
- {
- public float xMin, xMax, zMin, zMax;
- }
- public class PlayerController : MonoBehaviour {
- public float speed;
- public Boundary boundary;
- public float tilt;
- // Use this for initialization
- void FixedUpdate()
- {
- float moveHorizontal = Input.GetAxis("Horizontal");
- float moveVertical = Input.GetAxis("Vertical");
- Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
- GetComponent<Rigidbody>().velocity = movement * speed;
- GetComponent<Rigidbody>().position = new Vector3(
- Mathf.Clamp(GetComponent<Rigidbody>().position.x,boundary.xMin, boundary.xMax),
- 0.0f,
- Mathf.Clamp(GetComponent<Rigidbody>().position.z, boundary.zMin, boundary.zMax));
- GetComponent<Rigidbody>().rotation = Quaternion.Euler(0,0, GetComponent<Rigidbody>().velocity.x * -tilt);
- }
- }
- float moveHorizontal = Input.GetAxis("Horizontal");
- float moveVertical = Input.GetAxis("Vertical");
- float moveHorizontal = Input.GetAxis("Horizontal");
- float moveVertical = Input.GetAxis("Vertical");
- Debug.Log("Movement: " + moveHorizontal + ", " + moveVertical); // <-- add this
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement