Hello,
I implemented the Character Controller movement procedure in Chapter 4 for the SpaceMarine game object, and I received the following error:
NullReferenceException: Object reference not set to an instance of an object
PlayerController.Update () (at Assets/Scripts/PlayerController.cs:19)
The script is as follows:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float moveSpeed = 50.0f;
private CharacterController characterController;
// Start is called before the first frame update
void Start()
{
var characterController = GetComponent();
}
// Update is called once per frame
void Update()
{
Vector3 moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
characterController.SimpleMove(moveDirection * moveSpeed);
}
}
I attached this script to the SpaceMarine GameObject, and I have been successful in implementation up to to this point.
Other Information:
The Space Marine is a prefab and an instantiated GameObject in the hierarchy.
It inherits the parent MonoBehaviour transform component.
It implements a Character Controller.
It has a C# script attached named PlayerController.cs, which runs the script as it appears above.
Please let me know if there is anything you notice that I am doing wrong.
Here is a screenshot for the virtual sleuths.