Can anyone explain to me why I am getting this error NullReferenceException object reference not set to instance of an object. Im getting this issue in my game so I came to the live training and started watching the Saving and loading data tutorial. Followed it step by step and I am getting the same error i had in my own game.
Here is my GameControl Script attached to a GameControl object
using UnityEngine;
using System.Collections;
public class GameControl : MonoBehaviour {
public static GameControl control;
public float health;
public float exp;
void OnGUI()
{
GUI.Label (new Rect (10, 10, 100, 30), "Health" + health);
GUI.Label (new Rect (10, 40, 150, 30), "EXP" + exp);
}
}
Here is the adjust script attached to the main camera
using UnityEngine;
using System.Collections;
public class AdjustScript : MonoBehaviour {
void OnGUI()
{
if(GUI.Button(new Rect(10,100,100,30),"Health up"))
{
GameControl.control.health += 10;
}
if(GUI.Button(new Rect(10,140,100,30),"Health down"))
{
GameControl.control.health -= 10;
}
if(GUI.Button(new Rect(10,180,100,30),"Exp up"))
{
GameControl.control.exp += 10;
}
if(GUI.Button(new Rect(10,220,100,30),"Exp down"))
{
GameControl.control.exp -= 10;
}
}
}
That is it, super simple and identical to the code in the video. I am getting the error but he is not. Please Help!!
Thank you