The roll a ball script isn't working :((((
Hey guys, I am new to working with Unity and code. I am trying to continue the "Roll a Ball" tutorial working on the first part of scripts in video 2: "Moving the Player". After completely the script for adding force and direction to to the 'rigid body', "I attempt to play test the movement and it does not move at all. At the bottom of the screen it also states "NullReferenceException: Object reference not set to an instance of an object". This is painfully hard to find a solution for as I cannot find it anywhere else on the forums, youtube comments, etc. Please help and thanks!!!!
Here is my script:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerController : MonoBehaviour {
private Rigidbody rb;
void start ()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce (movement);
}
}
Answer by SteenPetersen · Jul 27, 2017 at 06:29 AM
You have a typo you mispelled start: use this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rb.AddForce(1, 0, 0);
}
}
Answer by AntonioSK · Jul 27, 2017 at 07:21 PM
Wow, thank you so much! It is finally working haha. I'm so happy it was a just a capitalization but so angry at the same time! Appreciate it. :)))
Anytime, just remember to mark answer as correct so others see it as well. Glad I could help.