NullReferencedException

Hi guys,

Im new with Unity and scripting. Im getting the following error:

Here is my script

#pragma strict

var rotateSpeed = 90;
var Acceleration = 3.5;

private var character : CharacterController;
private var trans : Transform;
private var speed = 0.0;

function Start () {
	character = GetComponent(CharacterController);
	trans = transform;

}

function Accelerate() {
	speed += Acceleration;
}

function Update () {
	var horizontal = Input.GetAxis("Horizontal");
	trans.Rotate(0, rotateSpeed * horizontal * Time.deltaTime, 0);
	
	if (Input.GetKeyDown(KeyCode.Space))
		Accelerate();
		
	character.Move(trans.forward * speed * Time.deltaTime);
}

Thanks in advance.

Since you don’t have a @require in your code, there’s the possibility that your object that carries this script doesn’t contain a CharacterController component on it. Make sure you add one.

Hi Diviner,

Thanks. But how do I do it exactly? I’m sorry. Im still learning.

EDIT: I think I figured it out. Forgot to put in. Character Controller in the Component Section.