• 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
-2
Question by jackbobinson · Feb 13, 2015 at 07:21 PM · charactermenudeathmain

Cannot implicitly convert type 'int' to 'bool'

I am getting this error when I try to say that my health is at 0 to load the level of my main menu

 public static int Health;
 
 void update ()
 {
 //continuously damage player
 DamagePlayer(1);
 if(Health <=0);
 Health =0;
 destroy (gameObject);
 Application.LoadLevel("scene1");
 }

Comment
Add comment · Show 3
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 Doireth · Feb 13, 2015 at 07:23 PM 0
Share

Please use the code formatting option. Your post is very hard to read.

avatar image jackbobinson · Feb 14, 2015 at 07:33 AM -1
Share

well thank you everyone.. kinda new to the whole posting on this. I did figure out what the problem was, i changed the destroy game object to a function called death and in that function i call the object to be destroyed and to load the level and it works that way... I do have a problem with the damage over time, I want to use Time.Deltatime but it wont let me. I wish i could copy and paste what I have i just don t know how :/

Show more comments

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by seriousitydevelopment · Feb 13, 2015 at 07:28 PM

The ; after your if statement should be replaced with a {

Don't know if this will solve the problem though.

replace

  • ;

with

  • {

Comment
Add comment · Show 1 · 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 Bonfire-Boy · Feb 14, 2015 at 12:52 AM 0
Share

That wouldn't produce the error described in the title though. You'd probably just get an "empty if statement" warning.

The only thing I can see in the code shown that might produce the error is line 6... if DamagePlayer() actually takes a bool.

But given the various mistakes in the code I doubt it's been copied-and-pasted from the actual source file. So maybe it's just as likely that the source has if (Health =0) and it's been "corrected" in transcription.

avatar image
-1

Answer by Kiwasi · Feb 13, 2015 at 11:21 PM

This is totally broken. Go back to the learn section, do the scripting tutorials over, and start again.

Here is a script for you that will compile, meets convention, and does something useful.

  public int health;
  
  void Update ()
  {
      health -= Time.deltaTime;
      if(health <=0){
          health =0;
          Destroy (gameObject);
          Application.LoadLevel("scene1");
      }
  }
Comment
Add comment · 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
0

Answer by bartm4n · Feb 13, 2015 at 11:40 PM

Please format your code with appropriate spacing and line breaks following some sort of standard, e.g.:

 public static int Health;
 
 void update () { 
     //continuously damage player 
     DamagePlayer(1); 
     
     if(Health <= 0){ 
         Health = 0; 
         Destroy (gameObject); 
         Application.LoadLevel("scene1"); 
     }
 }

After doing that, if the error persists, please indicate exactly which line the error is occurring on.

Another question, unrelated to the issue, do you know why are you declaring Health as a static? This would ordinarily be used to ensure that Health is the same value for all instances of your class.

Comment
Add comment · 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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

7 People are following this question.

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

Related Questions

How to get back to the main menu when dead? 1 Answer

Keeping character's data through levels 2 Answers

character death - In transitions settings, where is ‘can transition to self’? 3 Answers

Passing a variable through the main menu 2 Answers

2D Game: main menu button dont work 0 Answers


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