- Home /
help with boss death (bool)
Hi all, this is driving me mad, can anyone help?
What i'm trying to do is have my boss die and make an explosion, where am I going wrong?
currently, once the boss's health reaches 0, he just carries on, no death, no explosion.
this is my script :
var death : Transform;
var delay : int = 0;
var bossdead : boolean = false;
function Start(){
bossdead = false;
}
function Update(){
if(boss_healthbar.LIVES <= 0){
bossdead = true;
}
}
if(bossdead) {
Instantiate(death, transform.position, transform.rotation);
var boss = GameObject.FindWithTag("boss");
Destroy(boss);
yield WaitForSeconds(delay);
Application.LoadLevel(69);
}
It's really hard to read code like that, next time please click the little button with 1's and 0's in it and paste your code in there so it will be formatted.
What errors are you getting? Is the boss dying? Is the explosion happening? Is the boss being destroyed?
What is actually going wrong with this? You basically just posted some code and asked us to find the error without telling us what was wrong.
once the boss's health reaches 0 it doesn't die and no explosion
Answer by Sildaekar · Mar 10, 2014 at 07:38 PM
Did you populate the "death" variable? Also, did you apply the "boss" tag to the boss object?
Also you should delete yield WaitForSeconds(delay);
as it has no effect (you need to read up more on coroutines).
Also:
It looks like you have an extra bracket here:
function Update(){
if(boss_healthbar.LIVES <= 0){
bossdead = true;
}
}
Remove one of those last brackets, you are essentially closing out the Update() method and the rest of the code is getting run. You should be getting some compiler errors actually since the rest of the code isn't in a method.
death is populated with an explosion prefab. Boss tag is on boss. the yield for seconds has a value in the inspector which waits x amount of seconds.
this is my current script, but once the boss reaches 0 lives and gets destroyed i get multiple explosions (i think this is because its looping through the function update?)
var death : Transform;
var delay : int = 0;
var bossdead : boolean = false;
function Start(){
bossdead = false;
}
function Update(){
if(boss_healthbar.LIVES <= 1){
bossdead = true;
}
if(bossdead == true) {
Bossdeath();
}
}
function Bossdeath(){
Instantiate(death, transform.position, transform.rotation);
var boss = GameObject.FindWithTag("boss");
Destroy(boss);
yield WaitForSeconds(delay);
Application.LoadLevel(69);
}
Change it to this:
var death : Transform;
var delay : int = 0;
var bossdead : boolean = false;
function Start(){
bossdead = false;
}
function Update(){
if(boss_healthbar.LIVES <= 1){
if(!bossdead){
Bossdeath();
bossdead=true;
}
}
}
function Bossdeath(){
Instantiate(death, transform.position, transform.rotation);
var boss = GameObject.FindWithTag("boss");
Destroy(boss);
Application.LoadLevel(69);
}
Also like I said, yield WaitForSeconds(delay); will not work in Update(), it needs to be in a coroutine
If this answers your questions please don't forget to mark this answer :)