Hello ,I’m trying to make a simple moving character script (script from a tutorial) and when I want to check the few first step, this error show :
NullReferenceException: Object reference not set to an instance of an object
PlayerController.Move () (at Assets/Codes/PlayerController.cs:35)
PlayerController.FixedUpdate () (at Assets/Codes/PlayerController.cs:30)
PlayerController script :
public class PlayerController : MonoBehaviour {
//Variables
public float walkspeed;
Rigidbody rb;
Vector3 moveDirection;
void awake()
{
rb = GetComponent<Rigidbody> ();
}
// Update is called once per frame
void Update ()
{
//Direction
float horizontalMovement = Input.GetAxisRaw("Horizontal");
float verticalMovement = Input.GetAxisRaw("Vertical");
moveDirection = (horizontalMovement * transform.right + verticalMovement * transform.forward).normalized;
}
void FixedUpdate()
{
Move();
}
void Move()
{
rb.velocity = moveDirection * walkspeed * Time.deltaTime;
}
}
Please help me.