Sorry about this one, gang. I’ve tried and tried and have not been able to get this to work to my liking, which is surprising, since I’ve done similar things before with no issues. Am pretty certain that my problem is simply a matter of placement.
Here’s the deal: I have an enemy health script attached to an npc. He starts out with 199 hp. Hit him with a weapon, that hp lowers a bit, until eventually it runs out and he dies. Except, that he’s dying before I even hit him. Commenting out the “destroy” line solves the problem, but obviously not in the way I want, since now he won’t go away. Am hoping that a fresh set of eyes will be able to spot where I’m going wrong. Any help is of course humbly appreciated. God bless.
var Name = "Golgor";
var Exp = 140;
var GolgorHealth : int = 199;
var GolgorKilled = 0;
var hitSound : AudioClip;
//function Start(){
//if(PlayerPrefs.GetInt("GolgorKilled", 0) == 1){
//object.active = true;
//object.enabled = true;
//MedamomoGateOpen.GateOpen = true;
//Destroy(gameObject);
//}
//}
function OnTriggerEnter (other : Collider){
if (other.gameObject.name == "sword") {
GolgorHealth = -25;
AudioSource.PlayClipAtPoint(hitSound, transform.position);
animation.Play("GolgorHit");
death();
}
else
{
if (other.gameObject.name == "club")
{
GolgorHealth = -10;
AudioSource.PlayClipAtPoint(hitSound, transform.position);
animation.Play("GolgorHit");
death();
}
}
}
function death (){
if(GolgorHealth <= 0 )
if(GolgorKilled == 0 ){
GolgorKilled = 1;
yield WaitForSeconds(2.0);
Destroy(gameObject);
Playerhealth.curXp += Exp;
Playermoney.curMoney += 250;
PlayerPrefs.SetInt("GolgorKilled", 1);
Debug.Log( Name + " is killed");
}
}