- Home /
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");
}
Please use the code formatting option. Your post is very hard to read.
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 :/
This is a comment, not an answer. Converting for you.
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
{
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.
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");
}
}
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.
Your answer
Follow this Question
Related Questions
script to save and load a game 3 Answers
Main Menu scrpit not working 1 Answer
Any ideas to do a character selection 4 Answers
Main Menu issues when restart 1 Answer
How do I create a in-game music library that my character can use? 0 Answers