Hello
Im having trouble with my script I want it so when my enemys health = 0 it dies and Instantiate an exp object and the enemy dies with an explosion but when it hits the player it explodes takes life off the player but doesnt give exp heres my script
var maxHealth = 100;
var curHealth = 100;
var Playerdamage = 30;
var Enemydamage = 10;
var target : GameObject;
var explosion : GameObject;
var exp : GameObject;
function Update () {
AddjustCurrentHealthEnemy(0);
}
function AddjustCurrentHealthEnemy(adjE) {
curHealth += adjE;
if(curHealth < 0)
curHealth = 0;
if (curHealth > maxHealth)
curHealth = maxHealth;
if(maxHealth < 1)
maxHealth = 1;
if(curHealth < 1) { //die
var newExplosion:GameObject=Instantiate(explosion,transform.position,transform.rotation);
var newExp:GameObject=Instantiate(exp,transform.position,transform.rotation);
Destroy(gameObject);
}
}
function OnCollisionEnter(collision : Collision){
if(collision.gameObject.tag == "Bullet"){
curHealth -= Playerdamage;
}
if(collision.gameObject.Find("Player")){
target.GetComponent(PlayerHealth).AddjustCurrentHealthPlayer(-Enemydamage);
var newExplosion:GameObject=Instantiate(explosion,transform.position,transform.rotation);
Destroy(gameObject);
}
}
this works for when the enemy hits the player but when i shoot the enemy and it dies i loose health and there no exp. heres my other script
var maxHealth = 100;
var curHealth = 100;
var Playerdamage = 30;
var Enemydamage = 10;
var target : GameObject;
var explosion : GameObject;
var exp : GameObject;
function Update () {
AddjustCurrentHealthEnemy(0);
}
function AddjustCurrentHealthEnemy(adjE) {
curHealth += adjE;
if(curHealth < 0)
curHealth = 0;
if (curHealth > maxHealth)
curHealth = maxHealth;
if(maxHealth < 1)
maxHealth = 1;
if(curHealth < 1) { //die
var newExplosion:GameObject=Instantiate(explosion,transform.position,transform.rotation);
var newExp:GameObject=Instantiate(exp,transform.position,transform.rotation);
Destroy(gameObject);
}
}
function OnCollisionEnter(collision : Collision){
if(collision.gameObject.tag == "Bullet"){
curHealth -= Playerdamage;
}
if(collision.gameObject.tag == ("Player")){
target.GetComponent(PlayerHealth).AddjustCurrentHealthPlayer(-Enemydamage);
var newExplosion:GameObject=Instantiate(explosion,transform.position,transform.rotation);
Destroy(gameObject);
}
}
this works for when i shoot the enemy it dies i DONT loose health and the exp object appears. but all im changing is
if(collision.gameObject.Find("Player"))
to
if(collision.gameObject.tag == ("Player"))
im really confused can someone please help
Thanks.