C#, "object reference not set to an instance of an object"

Using the CharacterController.Move script from the Unity Script Reference site, and I get an error that says “object reference not set to an instance of an object.” I really have no idea what I’m doing wrong. Here’s the code:

using UnityEngine;
using System.Collections;

public class Script_PlayerController : MonoBehaviour {
    
	public float speed = 6.0F;
    public float jumpSpeed = 8.0F;
    public float gravity = 20.0F;
    private Vector3 moveDirection = Vector3.zero;
	
    void Update() {
        CharacterController controller = GetComponent<CharacterController>();
        if (controller.isGrounded) {
            moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
            moveDirection = transform.TransformDirection(moveDirection);
            moveDirection *= speed;
            if (Input.GetButton("Jump"))
                moveDirection.y = jumpSpeed;
            
        }
        moveDirection.y -= gravity * Time.deltaTime;
        controller.Move(moveDirection * Time.deltaTime);

Ok I think I’ve got it. The script is trying to access another script or component called Character Controller. It’s possible to add this component through the menu by the way of Component → Physics → Character Controller. My Player was falling through the map for a while, but all I had to do was raise the Player up a bit.

use

CharacterController controller = GetComponent<CharacterController>() as CharacterController;

instead of :

CharacterController controller = GetComponent#CharacterController#();

CharacterController controller = gameObject.GetComponent();

that should fix ya