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 /
This question was closed Sep 12, 2014 at 01:13 PM by Xain for the following reason:

The question is answered, right answer was accepted

avatar image
1
Question by Xain · Sep 07, 2014 at 12:42 PM · boolvoid

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.

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 Landern · Sep 07, 2014 at 12:44 PM 0
Share

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.

avatar image Xain · Sep 07, 2014 at 01:51 PM 1
Share

Thanks it's make sense now :D

1 Reply

  • Sort: 
avatar image
0
Best Answer

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
 }


Comment
Add comment · Show 4 · 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 Xain · Sep 07, 2014 at 01:50 PM 1
Share

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);
avatar image SuperMasterBlasterLaser · Sep 07, 2014 at 01:54 PM 0
Share

This means that you placed wrong arguments inside GUI.BOX do something like this: GUI.Box(new Rect(), "Your string");

avatar image Landern · Sep 07, 2014 at 01:59 PM 0
Share

@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.

GUI.Box documentation

avatar image Xain · Sep 07, 2014 at 02:55 PM 1
Share

Thanks for fast answers, i guess im gonnna open another topic.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

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


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