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 ?