0
using System.Collections;
using UnityEngine.EventSystems;

public class PlayerMovement : MonoBehaviour {
    private CharacterController controller;
    private Vector3 direction;
    public float speed = 15f;
    void start()
    {
        controller = GetComponent<CharacterController>();
    }
    void Update()
    {
        direction.z = speed;
        controller.Move(direction * Time.deltaTime);
    }  
}

Why i am getting this error? I am using unity5.3 this is the full error

NullReferenceException: Object reference not set to an instance of an object PlayerMovement.Update () (at Assets/Scripts/PlayerMovement.cs:16)

Llama
  • 25,925
  • 5
  • 49
  • 68

1 Answers1

0

Either controller or direction isn't initialized. Make sure they are before your call to Update().

Gama
  • 131
  • 4