" ArgumentException : GetComponent nécessite que le composant demandé 'PlayerMotor' dérive de MonoBehaviour ou Component ou soit une interface.
UnityEngine.Component.GetComponent[T] () (dans /Users/bokken/build/output/unity/unity/Runtime/Export/Scripting/Component.bindings.cs:42)
PlayerController.Start () (à Assets/PlayerController.cs:14) "
Pouvez-vous m'aider ?
Code : Tout sélectionner
using System;
using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
public class PlayerMotor : MonoBehaviour
{
private Vector3 velocity;
private Rigidbody rb;
private void Start()
{
rb = GetComponent<Rigidbody>();
}
public void Move(Vector3 _velocity)
{
velocity = _velocity;
}
private void FixedUdapte()
{
PerformMovement();
}
private void PerformMovement()
{
if(velocity != Vector3.zero)
{
rb.MovePosition(rb.position + velocity * Time.fixedDeltaTime);
}
}
}
Voici le deuxième code:
Code : Tout sélectionner
using System;
using UnityEngine;
[RequireComponent(typeof(PlayerMotor))]
public class PlayerController : MonoBehaviour
{
[SerializeField]
private float speed;
private PlayerMotor motor;
private void Start()
{
PlayerMotor.Start()
}
private void Update()
{
// Calculer la vélocité (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;
//On calcule la rotation du joueur en un vector3
float yRot = Input.GetAxis("Mouse X");
}
private class PlayerMotor
{
internal void Move(Vector3 velocity)
{
throw new NotImplementedException();
}
}
}