x


exp script accessing to leveling script

im making a game with a lvl system but i dont know why my exp script does not interac with the lvl script. My exp script is combine with a damage receiver script so when the target die it give a certan amount of exp but when i kill the target the exp does not add to the "accumulatedExperiencePoints" of the lvl script.I tried many thing but it doesn't seem to work.how can i make it work?

here is my lvl 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 here is my exp script:

var accumulatedExperiencePoints : int = 0;
var player : Leveing_Script;

if (hitPoints <= 0) {
    Destroy(gameObject);
    gameObject.Find("Player").GetComponent(Leveing_Script).accumulatedExperiencePoints += 10;

    }
more ▼

asked Oct 21 '10 at 10:42 PM

vincent dupuis morneau gravatar image

vincent dupuis morneau
19 7 8 9

You need an Update function in your exp script.

or

There's no object named Player with a "Leveing_Script" attached.

Oct 22 '10 at 05:01 PM Loius
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

i added a update function but the exp is stil not adding to the "accumulatedExperiencePoints" and i tcheck is the name of the object was correct and it was :S what shoud i do??

here is the full exp script:

var hitPoints = 100.0;
var deadReplacement : Transform;
var dieSound : AudioClip;
var accumulatedExperiencePoints : int = 0;
var player : Leveing_Script;

function Update () {
    if (hitPoints <= 0) {
    gameObject.Find("Player").GetComponent(Leveing_Script).accumulatedExperiencePoints += 10;
    Destroy(gameObject);
    }
}

function ApplyDamage (damage : float) {
    // We already have less than 0 hitpoints, maybe we got killed already?
    if (hitPoints <= 0.0)
        return;

    hitPoints -= damage;
    if (hitPoints <= 0.0)
    {
        Detonate();
    }
}

function Detonate () {
    // Destroy ourselves
    Destroy(gameObject);

    // Play a dying audio clip
    if (dieSound)
        AudioSource.PlayClipAtPoint(dieSound, transform.position);

    // Replace ourselves with the dead body
    if (deadReplacement) {
        var dead : Transform = Instantiate(deadReplacement, transform.position, transform.rotation);

        // Copy position & rotation from the old hierarchy into the dead replacement
        CopyTransformsRecurse(transform, dead);
    }
}

static function CopyTransformsRecurse (src : Transform,  dst : Transform) {
    dst.position = src.position;
    dst.rotation = src.rotation;

    for (var child : Transform in dst) {
        // Match the transform with the same name
        var curSrc = src.Find(child.name);
        if (curSrc)
            CopyTransformsRecurse(curSrc, child);
    }
}
more ▼

answered Oct 22 '10 at 07:16 PM

vincent dupuis morneau gravatar image

vincent dupuis morneau
19 7 8 9

never mind i found why it did not add the exp. its because my script was deliting the object befor the exp could be added so i deleted the Destroy(gameObject); in the function detonate and thanx for your help :D

Oct 22 '10 at 07:21 PM vincent dupuis morneau
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3418
x211
x4

asked: Oct 21 '10 at 10:42 PM

Seen: 758 times

Last Updated: Oct 22 '10 at 04:19 PM