Hello. Basically I have an experience system I am trying to implement. I want the player to be able to gain experience points PER KILL. I have two scripts one that is called EnemyDamageReceiver.js, and the other called ExperienceSystem.js. So I want it so when this is true : `
if(hitPoints <= 0.0){
GameObject.Find("Player").GetComponent(ExperienceSystem).GiveXP.(expVal);
}
Keep in mind that the script containing this code is attached to my enemy. Also in the same script I do have a variable set for expVal that looks like this:
var expVal : int = 20;
So now in the ExperienceSystem.js, it looks like this.
var guiTextEXP : GUIText;
var accumulatedExperiencePoints = 0;
var levelExpRequirements = 1000;
var currentLevel = 1;
var xp : int;
function GiveXP(addedXP : int)
{
if (addedXP < 0)
{
Debug.Log("Can't remove exp!");
return;
}
xp += addedXP;
if (accumulatedExperiencePoints >= levelExpRequirements)
{
levelExpRequirements += 1000;
currentLevel += 1;
guiTextEXP.text = accumulatedExperiencePoints+"/" + levelExpRequirements + "|" + currentLevel;
}
}
Now I simply want the value that is assigned to the expVal variable that is on my EnemyDamageReceiver.js to be sent to my accumulatedExperiencePoints variable on my ExperienceSystem.js whenever the enemy dies so that it gives him experience points. I have tried MANY different way to attempt this but have failed. I am just simply unclear and unsure what I am doing wrong. I am not that experienced in UnityScript. So please bare with me. That is why I am asking for help here so that I can get the hang of these simple things to move on to bigger things. Thank you so much if you are willing to help me. All ideas are appreciated! thank you again!