Object reference error

Hello everyone, I’m very new here and I’m trying to learn how to create simple games watching tutorial. But when I try to create a code in order to move my character this happens:

Here is my code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Playerctrl : MonoBehaviour {

public float speed;

Rigidbody2D rb;

//Use this for initialization
void start () {
rb = GetComponent<Rigidbody2D> ();
}

//Update is called once per frame
void Update () {

}

void FixedUpdate(){
float move = Input.GetAxis ("Horizontal"); // a or left = -1 d or right = 1

rb.velocity = new Vector2 (speed * move, rb.velocity.y);
}
}

And when I lauch my game to test this out I have the error:
NullReferenceException: Object reference not set to an instance of an object
Playerctrl.FixedUpdate () (at Assets/Scripts/Playerctrl.cs:24)

Can you help me ?

Does the object have a rigidbody on it?

If my character is an object yes he does

The Start() method is capitalized while yours is start(). Thus, it doesn’t get called at the beginning and the rb variable isn’t assigned.
PS: It’s not recommended to modify the Rigidbody’s velocity directly. Better use either Transform.Translate() or Rigidbody.MovePosition():

Oh thank you so much it finally works!
Okok I see I’m just following tutorial that’s why :wink: