Hello,
I’m a beginner in Editor Scripting. I’ve written two scripts - ‘CalculateStats.cs’ and ‘CalculateStatsEditor.cs’.
CalculateStats.cs contains some properties that I’ve created. CalculateStatsEditor.cs is basically editor script that accesses those properties. Whenever I attach CalculateStats.cs to the MainCamera, I get a NullReferenceException on Line 13 in ‘CalculateStats.cs’. If the script was already attached to the MainCamera, each time I click the the script in the Inspector, 2 or 3 NullReferenceExceptions get added in the Console.
What am I doing wrong?
using UnityEngine;
using System.Collections;
public class CalculateStats : MonoBehaviour {
private string _Name;
private int _Experience;
private int _Level;
public string Name
{
get{return _Name;}
set{_Name = value;}
}
public int Experience
{
get{return _Experience;}
set{_Experience = 200;}
}
public int Level
{
get{return _Level;}
set{
_Level = _Experience/1000;
}
}
}
using UnityEngine;
using UnityEditor;
using System.Collections;
[CustomEditor(typeof(CalculateStats))]
public class CalculateStatsEditor : Editor {
public override void OnInspectorGUI()
{
CalculateStats calcStat = (CalculateStats)target;
EditorGUILayout.LabelField("Player Name", calcStat.Name.ToString ());
}
}