So i have been working on improving my scripting for a while and i am trying to implement an experience system. Just a basic, kill something and it gives experience. Below i have put my ExperienceScript and EnemyHealth script.
ExperienceScript
var currentExperience : int;
var maxExperience : int = 100;
function GiveExperience ()
{
var experienceGain = EnemyHealth.experienceGain;
currentExperience += experienceGain;
Debug.Log("You Gained Experience");
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();
}
EDIT: Sorry about that, i am getting this error when the enemy gets to 0 health, instead of dieing i get this
NullReferenceException: Object reference not set to an instance of an object
EnemyHealth.Experience () (at Assets/Scripts/EnemyHealth.js:28)
EnemyHealth.Dead () (at Assets/Scripts/EnemyHealth.js:21)
EnemyHealth.Update () (at Assets/Scripts/EnemyHealth.js:9)