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