Question by
LettucePie · Nov 13, 2015 at 01:55 PM ·
scripting problemreferencestatic variableobject-reference-error
..Object reference not set to an instance of an object.. Error occuring for a public static script variable.
I'm trying to get a middle-man script to read a public float variable from a public static script, then push it to a UI text box attached to the middle-man script. I can get the public static script to debug.log the variable without a problem.
Here's the Middle-man or interpretor script that the error occurs on.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class UnitImportCombat : MonoBehaviour {
public Text button1;
// Use this for initialization
void Start () {
button1.text = "01. " + Unit01Data.stats.health;
Debug.Log(Unit01Data.stats.health);
}
}
Here's the Unit01Data script... I reduced amount of clutter on it, but please follow up if you think the extra bits are important. They're save and load data stucture stuff.
using UnityEngine;
using System.Collections;
using System;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using UnityEngine.UI;
public class Unit01Data : MonoBehaviour {
public static Unit01Data stats;
public float health;
public float mana;
public float exp;
Comment
Best Answer
Answer by LettucePie · Nov 14, 2015 at 10:17 AM
Solved my own error by adding
void Awake () { stats = this; }