- Home /
The question is answered, right answer was accepted
if Application.LoadLevel Error
Hello, im using C# and i want to add score to game over screen but there is have a problem
if (Application.LoadLevel("gameOver"))
GUI.Box (new Rect(50,50,100,100), score.ToString);
it gives me "Cannot implicity covert type 'void' to 'bool'" error.
Thanks for answers.
Application.LoadLevel("gameOver") does not return anything, it returns void, why? because it's loading the "gameOver" scene and thats that. An if statement is looking to compare something and end up with a boolean value(true/false) that can't happen when a method returns void.
Answer by SuperMasterBlasterLaser · Sep 07, 2014 at 12:48 PM
Because Application.LoadLevel is void function and returns nothing. Inside if you must only write expressions that will return true or false value.
I think youshould write something like that:
// Call elsewhere to load GameOver scene
Application.LoadLevel("gameOver");
// then
if (Application.loadedLevelName == "GameOver") {
// do something
}
Thanks for answer but now it gives me another error ;
`UnityEngine.GUI.Box(UnityEngine.Rect, string, UnityEngine.GUIStyle)' has some invalid arguments.
i still didn't figure out how to show score on game over screen with this code ;
GUI.Box (new Rect(50,50,100,100), "" , score.ToString);
This means that you placed wrong arguments inside GUI.BOX do something like this: GUI.Box(new Rect(), "Your string");
@Xain, if your original question is answered, please mark and close this question, open another with the script's that are relevant to your new problem.
But i'll throw you a bone.
GUI.Box has 5 overrides(meaning 6 methods that take different combinations of parameters/arguments.
static void Box(Rect position, string text);
static void Box(Rect position, Texture image);
static void Box(Rect position, GUIContent content);
static void Box(Rect position, string text, GUIStyle style);
static void Box(Rect position, Texture image, GUIStyle style);
static void Box(Rect position, GUIContent content, GUIStyle style);
You're passing, (Rect, string(even though it's empty), string)
You will notice that not a one matches your usage, which means you've made a mistake.
Thanks for fast answers, i guess im gonnna open another topic.
Follow this Question
Related Questions
Check if a function is no longer being called? 3 Answers
I'm having problems with bools resetting within a function 0 Answers
How to make a file run if a void has undefined coordinates? 1 Answer
How to make on/off-like gui-button? 3 Answers
Why does Unity mean with :Cannot implicitly convert type `void' to `bool' ? 3 Answers