How can i make it give u a certain xp everytime u kill someone?

basically i have this script

`var guiTextEXP : GUIText;
var accumulatedExperiencePoints : int = 0;
var levelExpRequirements : int = 1000;
var currentLevel : int = 1;

function Update () 
{    
if(accumulatedExperiencePoints >= levelExpRequirements) 
{        levelExpRequirements += 1000;        currentLevel += 1;    }    
guiTextEXP.text = accumulatedExperiencePoints+"/" + levelExpRequirements + "|" + currentLevel;
}`

and it works fine but now i need something to make it give me a certain amout of xp per kill...

Updated

Broadly speaking, you'd probably want each enemy to have a script containing variables dictating their health/xp. Then every time you applied damage to them, you'd check if their health was <= 0, and if so, kill them (death sound, etc) and increment the player xp by the specified amount.

Looking at your code (link in comments), you could add a variable to the EnemyDamageReceiver (assuming it's attached to every enemy).

var expVal : int = 20;

Then in ApplyDamage(), you'd add a line to find the Player, get the ExperienceSystem component (assuming it's attached to the Player) and then GiveXP to a certain value.

if (hitPoints <= 0.0) {
    GameObject.Find("Player").GetComponent(ExperienceSystem).GiveXP(expVal);
    // Start emitting particles
    (everything else here...)
    }

In the ExperienceSystem, you'd need to add a GiveXP function. Mike provided a decent example in the link I've commented, so I'll reuse it here.

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;
    }
}

Note that I also extracted the level-up check from your Update() loop, because it's not necessary to check that every frame - only when the player actually gains experience.

Hope this sets you on the right track.


You seem to keep asking the same question, adding slightly more detail each time (Q18343: Experience System & Q18579: Experience System). Your script here is just a copy/paste of xToxicInferno's answer from the second link. Do you have any other code of your own?

Happy to take a look at bugs in any code you might have, but take a crack at it first. Or, if you're inexperienced with javascript/games-programming, you might want to try one of the tutorials to get a hang of Unity.