using UnityEngine;
[RequireComponent(typeof(PlayerMotor))]
public class PlayerController : MonoBehaviour {
[SerializeField]
private float speed = 5f;
[SerializeField]
private float lookSensitivity = 3f;
private PlayerMotor motor;
void Start ()
{
motor = GetComponent<PlayerMotor> ();
}
void Update ()
{
float _xMov = Input.GetAxisRaw ("Horizontal");
float _zMov = Input.GetAxisRaw ("Vertical");
Vector3 moveHorizontal = transform.right * _xMov;
Vector3 moveVertical = transform.forward * _zMov;
Vector3 velocity = (moveHorizontal + moveVertical).normalized * speed;
//Apply movement
motor.Move (velocity);
//Calculate rotation as 3D vector (turning around)
float _yRot = Input.GetAxisRaw("Mouse X");
Vector3 _rotation = new Vector3 (0f, _yRot, 0f) * lookSensitivity;
//Apply rotation
motor.Rotate(_rotation);
}
//Calculate camera rotation as 3D vector (turning around)
float _xRot = Input.GetAxisRaw("Mouse Y");
Vector3 _cameraRotation = new Vector3 (_xRot, 0f, 0f) * lookSensitivity;
//Apply camera rotation
motor.RotateCamera (_cameraRotation)
}