hello everyone. i have a class as following:
using UnityEngine;
using System.Collections;
public class CheckPointManager : MonoBehaviour {
public static CheckPointManager instance;
public GameObject player;
public bool CP1; // a boolean that returns true if the first checkpoint has benn reached
public bool CP2;
public Vector3 CP1SP; // check point 1 spawn position
public Vector3 CP2SP;
public float CP1ST; // check point 1 skip time
public float CP2ST; // check point 2 skip time
AudioSource audioSource;
// Use this for initialization
void awake () {
DontDestroyOnLoad (gameObject);
instance = this;
audioSource = player.GetComponent<AudioSource> ();
}
// Update is called once per frame
void Update () {
if (!CP1 && audioSource.time > CP1ST) {
CP1 = true;
CP1SP=player.transform.position;
}
}
}
i have set the player GameObject in the inspector and i have checked everything on the inspector side and they are good. but still i get the error
“NullReferenceException: Object reference not set to an instance of an object”
when i double click the error it takes me to line 1 of the update function. specifically the problem seems to be invoking audioSource.time.