I am trying to make a simple experience script that when the enemy dies he rewards my player with 50 exp but when the enemy dies it is not giving my character any experience. I get the following error when my enemy dies.
NullReferenceException: Object reference not set to an instance of an object
EnemyHealth.Experience () (at Assets/Scripts/EnemyHealth.js:27)
EnemyHealth.Dead () (at Assets/Scripts/EnemyHealth.js:21)
EnemyHealth.Update () (at Assets/Scripts/EnemyHealth.js:9)
ExperienceScript
var currentExperience : int;
var maxExperience : int = 100;
function GiveExperience ()
{
var experienceGain = EnemyHealth.experienceGain;
currentExperience += experienceGain;
if(currentExperience >= maxExperience)
{
Debug.Log("LEVEL UP!");
}
}
EnemyHealth
var Health = 100;
static var experienceGain : float = 50;
function Update ()
{
if(Health <= 0)
{
Dead();
}
}
function ApplyDamage (Damage : int)
{
Health -= Damage;
}
function Dead ()
{
Destroy(gameObject);
Experience();
}
function Experience ()
{
var experienceScript : ExperienceScript;
experienceScript.GiveExperience();
}