Alright, so I made a script and attached it to an object, and when ever I shoot the object, it gets the level of the player and multiplies it by 1 (which now that i think about it, thats pointless). any way once health hits zero, the object explodes. This all works. But its also supose to add experience referncing the players script. but it doesn’t. I’ve tried restarting unity and everything. So I’m wondering if theres something wrong with my script. here it is:
var health = 5.0;
var explosion:Transform;
function OnCollisionEnter(hit:Collision){
var level = gameObject.Find("Player").GetComponent(Level);
var playerLevel = level.level;
if(hit.collider.tag == "Fire Ball"){
health -=1.0 * playerLevel;
checkhealth();
}
}
function checkhealth(){
var level = gameObject.Find("Player").GetComponent(Level);
var playerExp = level.experience;
if(health<=0.0){
playerExp += 50.0;
Instantiate(explosion, transform.position, transform.rotation);
Destroy (gameObject);
}
}