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
0
Question by DC168 · Oct 21, 2013 at 07:13 PM · guionguiguistyle

GUI works fine in editor, but not in build

I have:

  1. GUITexture attached to an object

  2. A script that has GUIStyles created for the Textfield and Buttons that are created in OnGUI(). This script is attached to the same object in number 1

  3. 3 GUIText objects each separate from the above.

  4. A script that enables the GUITexture and the script in number 1 and 2 respectively

This is how it is supposed to work: When I cross the finish line, number 4 script enables number 1 GUITexture component and number 2 script component. The script component uses one of number 3's GUIText objects to show you your best lap time, and also makes a GUI.Textfield for name entry and 2 GUI.Buttons for "Submit" and "Skip". If you hit "Submit" the script will submit the time. No matter which button you press, The remaining 2 GUIText objects from number 3 will show you the top 10 best times.

For some reason, when I run it in editor, everything works 100%, but when I'm in different kinds of builds, the results vary.

When I am in a webplayer, The GUITexture and the textfield and buttons appear, but the textfield and buttons are plain and have no evidence of GUIStyles. When I click one of the buttons, the score gets submitted but I do not get the fastest times showing.

When I am in a standalone build, the GUITexture shows up, but nothing else does. If I remove the GUIStyle parameter of the GUI.Textfield and GUI.Button, they show up.

Why am I getting these variations and how can I fix it?

Code below:

 void  Start ()
         {
             Names.text = "";
             Times.text = "";
             YourBestTime.text = "Your Best Lap: " + bestTime + "\nEnter your name:";
 
             //StartCoroutine(GetTimes("Test"));
             
         }
         
     void Update()
     {
         if (!ShowButtons && !GettingTimes)
         {
             StartCoroutine(GetTimes());
             GettingTimes = true;
         }
     }
 
     IEnumerator GetTimes ()
     {    
         Debug.Log("Getting times");
         YourBestTime.text = "Loading Best Lap Times";
         WWW times_get = new WWW(GetTimesUrl);
         yield return times_get;
         WWW names_get = new WWW(GetNamesUrl);
         yield return names_get;
         
         if(times_get.error != null || names_get.error != null) 
         {
             print("There was an error retrieiving the data: " + names_get.error + times_get.error);
         } 
         else 
         {
             Times.text = times_get.text;
             Names.text = names_get.text;
             YourBestTime.text = "Your Best Lap: " + bestTime;
         }    
     }
     
     IEnumerator PostLapTime (string Name, string LapTime)
     {
         string hash= MD5.Md5Sum(Name + LapTime + secretKey); 
         string bestTime_url = SubmitTimeUrl + "&Name=" + WWW.EscapeURL(Name) + "&LapTime=" + LapTime + "&hash=" + hash;
             
         Debug.Log (bestTime_url);
         // Post the URL to the site and create a download object to get the result.
         WWW hs_post = new WWW(bestTime_url);
         //label = "Submitting...";
         yield return hs_post; // Wait until the download is done
         if (hs_post.error != null) 
         {
             print("There was an error posting the lap time: " + hs_post.error);
             //label = "Error: " + hs_post.error;
             //show = false;
         }
         else
         {
             Debug.Log("Posted: " + hs_post.text);        
             ShowButtons = false;
             PostingTime = false;
         }
     }
     
     void OnGUI()
     {
         if (ShowButtons)
         {
             //makes text box            
             nameString = GUI.TextField( new Rect((Screen.width/2)-111, (Screen.height/2)-130, 222, 25), nameString, 20, TextboxStyle);
 
             if (GUI.Button( new Rect( (Screen.width/2-74.0f), (Screen.height/2)- 90, 64, 32), "Submit", ButtonStyle))
             {
                 //SUBMIT TIME
                 if (nameString == "")
                 {
                     nameString = "Player";
                 }
                 if (!PostingTime)
                 {
                     StartCoroutine(PostLapTime(nameString, bestTime));
                     PostingTime = true;
                 }
                 
             }
             else if (GUI.Button( new Rect( (Screen.width/2+10.0f), (Screen.height/2)- 90, 64, 32), "Skip", ButtonStyle))
             {
                 ShowButtons = false;
             }
         }
     }
 }
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
0
Best Answer

Answer by DC168 · Oct 22, 2013 at 04:03 AM

The reason it wasn't working was because I had C# and Javascript scripts with the same class name. Thanks!

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 Cherno · Oct 21, 2013 at 11:18 PM

Check the file output_log.txt in you project folder/buildname/buildname_Data directory, if there are any errors in the log.

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

15 People are following this question.

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

Related Questions

Setting up GUIStyles, best practice. 1 Answer

Optimizing OnGUI - Too many gui elements? 2 Answers

How to use GUIStyles in OnInspectorGUI? 1 Answer

Making a text box appear after a certain gameObject is destroyed 0 Answers

NullreferenceException, BeginScrollView style change 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