Hi !
I am really a noob in C + coding, so I would like someone to help me; D on the console there are three errors that I cannot fix, look at the screens and the sripts
using UnityEngine;
[RequireComponent(typeof(PlayerMotor))]
public class PlayerController : MonoBehaviour
{
[SerializeField]
private float speed;
[SerializeField]
private float mouseSensitivity;
private PlayerMotor motor;
private void Start()
{
motor = GetComponent<PlayerMotor>();
}
private void Update()
{
// Calculer la vélociter (la vitesse) du mouvement de notre joueur
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;
motor.Move(velocity);
// Calculer la rotation du joueur en un Vector3
float yRot = Input.GetAxisRaw("Mouse X");
Vector3 rotation = new Vector3(0, yRot, 0) * mouseSensitivity;
motor.Rotate(rotation);
}
// Calculer la rotation de la caméra en un Vector3
{
float xRot = Input.GetAxisRaw("Mouse Y");
Vector3 cr = new Vector3(xRot, 0, 0) * mouseSensitivity;
motor.RotateCamera(cr);
}
}
using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
public class PlayerMotor : MonoBehaviour
{
[SerializeField]
private Camera cam;
private Vector3 velocity;
private Vector3 rotation;
private Vector3 cr;
private Rigidbody rb;
private void Start()
{
rb = GetComponent<Rigidbody>();
}
public void Move(Vector3 _velocity)
{
velocity = _velocity;
}
public void Rotate(Vector3 _rotation)
{
rotation = _rotation;
}
public void RotateCamera(Vector3 _cr)
{
cr = _cr;
}
private void FixedUpdate()
{
PerformMouvement();
PerformRotation();
}
private void PerformMouvement()
{
if(velocity != Vector3.zero)
{
rb.MovePosition(rb.position + velocity * Time.fixedDeltaTime);
}
}
private void PerformRotation()
{
rb.MoveRotation(rb.rotation * Quaternion.Euler(rotation));
cam.transform.Rotate(-cr);
}
}
