I have 2 scripts and iam trying to acces the array thats made in script 1 but it gives me a nullreferenceexception when i press the start button (which calls Startgame()). Strangely when i use the debug.log in the first script it gives me the corrrect value 100 when i start the game. Game.current.Progress also doesnt have this problem it just works as i expected it to but this is not a array. Is this a bug? Kinda confused now. Do i have to reference a array in a different way than a normal variable?
Script 1:
using UnityEngine;
using System.Collections;
[System.Serializable]
public class Game {
public static Game current = new Game ();
public int Progress;
public float[] Scores;
public Game () {
Progress = new int();
Scores = new float[2];
Scores[0] = 100;
Debug.Log (Scores [0]);
}
}
Script 2 :
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Menucontroller : MonoBehaviour {
void Start (){
SaveLoad.Load ();
foreach (Game g in SaveLoad.savedGames) {
Game.current = g;
}
if (Game.current.Progress == 0) {
Game.current.Progress = 1;
}
}
public void StartGame () {
Application.LoadLevel (2);
Debug.Log ((Game.current.Scores)[0]);
}
Etcetcetc