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 /
avatar image
-1
Question by dwedge · May 08, 2012 at 02:16 AM · guionguiif-elsepop-up

Please help I don't understand what is wrong.

Okay I am trying to make a GUI pop up after completing a set number of laps but I'm getting all these errors with the coding that I have put in saying to put something in instead of what I have and when I do what it is asking it just brings up even more errors. My code is in Javascript, I have a lot of things commented out because they worked and I wanted to keep them in so if I fail at adding this pop up I can have my original coding. If at all possible when explaining what I did wrong could you make it as thorough and simple as possible because I am extremely new to programming and can barely understand it Thank you very much for your help.

function OnTriggerEnter(other : Collider){

 if (score <= 2){



     score = score + 1;



     print(score);

     }







 else

 {

     function OnGUI()

     {

      //(Application.LoadLevel("Tutorial Level"));

      // Make a group on the center of the screen

         GUI.BeginGroup (Rect (Screen.width / 2 - 50, Screen.height / 2 - 50, 100, 100));

     // All rectangles are now adjusted to the group. (0,0) is the topleft corner of the group.



     // We'll make a box so you can see where the group is on-screen.

         GUI.Box (Rect (0,0,100,100), "Do you want to continue with the Tutorial or move on to the real tracks?");

         if (GUI.Button (Rect (10,40,80,30), "Yes"))

             {

             Application.LoadLevel("Tutorial Level");

             }

         if (GUI.Button (Rect (30,60,100,50), "No"))

             {

             Application.LoadLevel("Title GUI");

             }



     // End the group we started above.

     GUI.EndGroup ();

      }

}

Comment
Add comment · Show 1
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 kolban · May 08, 2012 at 03:29 AM 0
Share

Please spend more time describing the nature of your question in the topic of the posting.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Nooch · May 08, 2012 at 02:52 AM

The OnGUI function shouldn't be inside OnTriggerEnter, it should be on it's own. OnGUI is a special built-in function, that is run multiple times every frame. So, it's constantly checking whether there are commands inside it to execute (this is also why it can be slow, when it is used too often).

To trigger the dialog, you could use a boolean (true / false) to tell OnGUI whether it should display your message box.

 var showDialog : boolean; // can be set to true or false, to decide whether to show the UI
 var score : int; // for the score
 
 function OnTriggerEnter(other : Collider)
 {
      if (score <= 2)
      {
           score = score + 1;
           print(score);
      }
      else
      {
           showDialog = true; // show the UI
      }
 }

 function OnGUI()
 {
      if (showDialog) // if the showDialog boolean is true ...
      {
           GUI.BeginGroup (Rect (Screen.width / 2 - 50, Screen.height / 2 - 50, 100, 100));
           GUI.Box (Rect (0,0,100,100), "Do you want to continue with the Tutorial or move on to the real tracks?");
           if (GUI.Button (Rect (10,40,80,30), "Yes"))
           {
                // load level
           }
           if (GUI.Button (Rect (30,60,100,50), "No"))
           {
                // load level
           }
           GUI.EndGroup();
      }

  }
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

6 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Hiding OnGUI? 1 Answer

[Solved] GUI Error? 1 Answer

How to be specific and universal with your onGUI controls? 1 Answer

Help! Why doesn't this work? GUI/Static vars Help! Javascript 1 Answer


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