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)

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86

1 Answers1

0

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

Gama
  • 141
  • 4