Gaining experience from enemies killed?
So i use this script for my player's health as well as the Experience he gets to level up. My question is how should i edit it so that i will able to get some XP from the enemies i kill? Thanks!
var maxHealth : int = 100; var curXP : int = 0; var maxXP : int = 240; var level : int = 1; function Start(){ healthRegen(); }
function OnGUI(){ GUI.Box(new Rect(5,405,200,20), curHealth + "/" + maxHealth); GUI.Box(new Rect(5,430,200,20), "Level " + level + " XP " + curXP + " / " + maxXP);
if(curXP == maxXP){
levelUpSystem();
}
if(curHealth < 0){
curHealth = 0;
}
if(curHealth > maxHealth){
curHealth = maxHealth;
}
if(Input.GetKeyDown("e")){
curHealth -= 10;
}
if(Input.GetKeyDown("r")){
curXP += 10;
}
} function healthRegen() { for(i=1;i>0;i++){
yield WaitForSeconds(0.5);
if(curHealth < maxHealth){
curHealth++;
}
}
} function levelUpSystem(){ curXP = 0; maxXP = maxXP + 50; level++;
maxHealth += 100;
}
Answer by Makarei · Oct 28, 2015 at 01:04 PM
On your enemy script, just before the enemy dies, right before the enemy gameObject is removed. add this code.
curXP += 10;
But it might not work straight away, as you will need to make the enemy script recognises what curXP actually is. watch some tutorials if you get stuck.
Your answer
Follow this Question
Related Questions
Error : BCE0018 Enemy ai 0 Answers
Enemy Health Won't go Down 1 Answer
Idle , Move and Attack animations 0 Answers
Need help with a levelUp system... 1 Answer
Could I get some help updating this code to unity 5? 0 Answers