Hi, I’ve been looking around on here quite a bit for help but this one I can’t seem to find the answer to; sorry if there is one which I didn’t find.
So I got a ‘GameManager’ Script which is where all the data is stored which is required by multiple scripts and will do other things later on.
public int questID = 1;
public int[] journelQuests = {10,10,0,0,0,0,0,0,0,0,0,0};
public static GameManager instance = null;
void Awake()
{
//Check if instance already exists
if (instance == null)
//if not, set instance to this
instance = this;
//If instance already exists and it's not this:
else if (instance != this)
//Then destroy this. This enforces our singleton pattern, meaning there can only ever be one instance of a GameManager.
Destroy(gameObject);
//Sets this to not be destroyed when reloading scene
DontDestroyOnLoad(gameObject);
}
and I can successfully call from this the ‘questID’ and add use that in a different script but I can’t do the ‘journelQuests’.
the code I am using to use the array in the other script is here
void Awake () {
for(int i = 0; i < 10; i++){
jQ[i] = GameManager.instance.journelQuests[i];
Debug.Log ("jQ = " + jQ[i]);
if(jQ[i] == 0){
jT[i].enabled = false;
jT[i+1].enabled = false;
}
else
{
GetData ();
jT[i].text = name;
jT[i+1].text = desc;
}
i++;
jQ[i] = GameManager.instance.journelQuests[i];
}
}
the error is - NullReferenceException: Object reference not set to an instance of an object
thanks for any help in advance and this is my first post so if I forgotten to state something or the format is wrong just say and I will happily rectify it.
Thanks
Isaac