On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Help with Project

A topic by thoted49 created Feb 20, 2021 Views: 129 Replies: 2
Viewing posts 1 to 2

New

Hi! I am New to Unity and the I have a problem with my script

Here is the script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour {

public float speed;
public float jumpForce;
public float moveInput;

private Rigidbody2D rb;

void start(){
rb = GetComponent<Rigidbody2D>();
}

void FixedUpdate(){

moveInput = Input.GetAxis("Horizontal");
rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
}

}


And here is the error message:

NullReferenceException: Object reference not set to an instance of an object
PlayerController.FixedUpdate () (at Assets/PlayerController.cs:20)
Submitted

You've accidentally created a method called void start() instead of void Start() with capital S. 

Either that or you don't have a Rigidbody2D on your object connected with the script. 

Hope that solves it

Thank you So much! :) I worked on the movement for the past 5 days!