Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Tamms · Aug 21, 2016 at 05:45 PM · menuongui

Problem with give up -button

Hi, this is my first project in Unity and I'm making a simple 3D platformer. (I'm on a course where we learn the basics of making 3D and 2D games in Unity) Every time you finish/fail a level, you see a screen that says "Level Completed!", "Continue" or "Level Failed!", "Restart". I'm trying to give the player the option to give up but I can't get it working. We were given the following script:

 void OnGUI() {
         GUI.skin.label.fontSize = 20;
         GUI.skin.label.alignment = TextAnchor.MiddleLeft;
         if (levelComplete) {
             
             if (LevelEndMessage("Level completed!", "Continue"))
             {
                 int nextLevel = Application.loadedLevel + 1;
                 if (nextLevel >= Application.levelCount) nextLevel = 0;
                 Application.LoadLevel(nextLevel);
             }
         }
         else if (levelFailed) {
             
             if (LevelEndMessage("You tried.", "Keep trying"))   
                 Application.LoadLevel(Application.loadedLevel);
             if (GUI.Button(new Rect(Screen.width/2 - 200/2, Screen.height/2 + 100, 200, 50) "Give up")) Application.LoadLevel(0);
         }
 
         else {
             GUI.skin.label.alignment = TextAnchor.MiddleLeft;
             GUI.Label(new Rect(10, 10, 200, 30), "Time:" + (Time.time - startTime).ToString("#"));
             GUI.Label(new Rect(10, 40, 200, 30), "Collected:" + collected + "/" + numTreasures);
         }
     }

and I can't get it working. If I switch the

 else if (levelFailed) {
                 
                 if (LevelEndMessage("You tried.", "Keep trying"))   
                     Application.LoadLevel(Application.loadedLevel);
                 if (GUI.Button(new Rect(Screen.width/2 - 200/2, Screen.height/2 + 100, 200, 50) "Give up")) Application.LoadLevel(0);

for

 else if (player == null) {
 //changed that ^                
                 if (LevelEndMessage("You tried.", "Keep trying"))   
                     Application.LoadLevel(Application.loadedLevel);
                 //if (GUI.Button(new Rect(Screen.width/2 - 200/2, Screen.height/2   //+ 100, 200, 50) "Give up")) Application.LoadLevel(0);
 //remove that ^

I can play the game and restart after death, but I can't give up. I'm a beginner (at best) at coding so I don't know if this is enough information for troubleshooting. The game won't run and it gives the following errors for the line that I removed: "A new expression requires () or [] after type" and "Internal compiler error during parsing, Run with -v for details".

Thank you and sorry if this is a common rookie mistake that I should be able to fix on my own.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by IsaiahKelly · Aug 21, 2016 at 06:12 PM

Looks like you're missing a comma (,) right before the "Give up" string in your button code.

Tip: Double click on any error message in the console to be taken directly to the line of code in your script that's causing the issue. You should then see a red line under the part of code that's causing the problem, and hovering over that part should give you additional info.

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 Tamms · Aug 22, 2016 at 05:05 AM

Thank you, it was the missing comma and thanks for the tip!

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.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Pause menu Change 0 Answers

Writing dropdown selections to file 1 Answer

Open Menu After Animation 1 Answer

How to use this menu (skins) in my game? 0 Answers

Responsive UI 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