Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
-1
Question by carter-carl30 · Mar 10, 2014 at 07:21 PM · booleanif statementdeath

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);
 
 }
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Sildaekar · Mar 10, 2014 at 07:24 PM 0
Share

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.

avatar image carter-carl30 · Mar 10, 2014 at 07:29 PM 0
Share

once the boss's health reaches 0 it doesn't die and no explosion

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image carter-carl30 · Mar 10, 2014 at 07:50 PM 0
Share

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);
 
 }
avatar image Sildaekar · Mar 10, 2014 at 08:33 PM 0
Share

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

avatar image Sildaekar · Mar 12, 2014 at 12:17 AM 0
Share

If this answers your questions please don't forget to mark this answer :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

(C#) If statements based on variables in another script 1 Answer

Some Boolean "Action" Trouble 2 Answers

I'm having trouble setting a bool. 2 Answers

2D game: When going from left input to right input fast the player stops moving 0 Answers

How to change boolean state based on User Input? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges