Question by
Walkerdude311 · Jan 30, 2016 at 04:21 AM ·
c#physicsplayer movementcontrol
Roll a Ball Tutorial error
Been at this for an hour and I don't know what to do Getting "NullReferenceException: Object reference not set to an instance of an object Playerconroller.FixedUpdate () (at Assets/Scripts/Playerconroller.cs:20)"
using UnityEngine;
using System.Collections;
public class Playerconroller : 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);
}
}
Comment
Answer by Trigary · Jan 30, 2016 at 07:13 AM
Sending us the tutorial would help :)
Try changing the 10th line to:
rb = transform.GetComponent<Rigidbody> ();
Does your ball have a rigidbody attached? If no, attach one to it :)