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 /
avatar image
0
Question by qsm · May 20, 2011 at 08:11 PM · guionguilabels

GUILayout.Label is not displaying on level load

I have a script that is checking a line from a text file and then displaying the word using Labels. I call the function that gets the line in Start() and my GUILayout.Label is being run in OnGUI(). I also call the function to get a line on a button press in OnGUI(). Problem is, that the Layout will only display when I press the button, but not on the first check of OnGUI() after Start() runs. I have verified that the I am getting a valid word to display in Start(), so I have no idea why the Label is not displaying. my code follows:

  function Start()
 {
     Debug.Log("Script has Started");
     if(newgame == true)
     {
         newgame = false;
         word = "";
         GetWord();
         
     }
 
 }
 function GetWord()
 {
         keyboardInstance.win = false;
         keyboardInstance.played = false;
         keyboardInstance.rightLetterCount = 0;
         keyboardInstance.wrongCount = 0;
         keyboardInstance.a = a;
         keyboardInstance.b = b;
         keyboardInstance.c = c;
         keyboardInstance.d = d;
         keyboardInstance.e = e;
         keyboardInstance.f = f;
         keyboardInstance.g = g;
         keyboardInstance.h = h;
         keyboardInstance.i = i;
         keyboardInstance.j = j;
         keyboardInstance.k = k;
         keyboardInstance.l = l;
         keyboardInstance.m = m;
         keyboardInstance.n = n;
         keyboardInstance.o = o;
         keyboardInstance.p = p;
         keyboardInstance.q = q;
         keyboardInstance.r = r;
         keyboardInstance.s = s;
         keyboardInstance.t = t;
         keyboardInstance.u = u;
         keyboardInstance.v = v;
         keyboardInstance.w = w;
         keyboardInstance.x = x;
         keyboardInstance.y = y;
         keyboardInstance.z = z;
         for (keyboardInstance.keyIndex = 0; keyboardInstance.keyIndex < 26; keyboardInstance.keyIndex++)
         {
             keyboardInstance.keyPressed[keyboardInstance.keyIndex] = false;
         }
         var sr : StreamReader = new StreamReader(path);
         var fileContents = sr.ReadToEnd();
         sr.Close();
     
         var randomNumber = Random.Range(0, numWords);
         var i : int = randomNumber;
     
         var lines = fileContents.Split("\n"[0]);
         
         
         for (line in lines[i]) {
             word += line;
         }
         textureArray = new Texture[(word.length - 1)];
         dashWidth = Screen.width/(word.length - 1);
         for (index = 0; index < (word.length - 1); index++){
             
             
             
             textureArray[index] = underscore;
         }
         activeWord = true;
         Debug.Log(word);
 }
 
 function OnGUI () {
     
     if (word != ""){
     
     GUI.Label(Rect(Screen.width/2,Screen.height/2,70,70),textureArray[0]);
     GUILayout.BeginArea(Rect(Screen.width/2 - ((word.Length - 1) * 70)/2,Screen.height - Screen.height/2,70 * (word.Length - 1),(Screen.height - Screen.height/2)/2));
         GUILayout.BeginHorizontal();
 
             for (counter = 0; counter < chars; counter++)
             {
                 
                 GUILayout.Label(textureArray[counter]);        
                 
             }
             
 
         GUILayout.EndHorizontal();
     GUILayout.EndArea();
     activeWord = false;
     }
     
     
     if (GUI.Button(Rect(20,260,100,100),"",newGame)){
         if (word != ""){
             word = "";
             GetWord();
         }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by DaveA · May 20, 2011 at 09:11 PM

Are you sure newgame is true before Start? Is it declared like var newgame = true; ?

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 qsm · May 20, 2011 at 09:14 PM 0
Share

Yes, I am setting newgame = true in the OnLevelWasLoaded() function, which is the first part of the script to run.

avatar image DaveA · May 20, 2011 at 09:47 PM 0
Share

Are we sure that runs before Start()?

avatar image qsm · May 20, 2011 at 10:18 PM 0
Share

Yes, I have sent comments to the Debug.Log() and have confirmed the the script runs in the order of OnLevelWasLoaded() -> Awake() -> Start() -> OnGUI()

avatar image DaveA · May 20, 2011 at 10:56 PM 0
Share

In Start you set word = ""; an in OnGUI, will only display the empty-string button if word == "" I would find another condition or set word = " " or something like that.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

OnGUI called after LateUpdate screwing up debug text database 1 Answer

Same GUI script showing up in different places 0 Answers

Free Gui solutions 2 Answers

Unity 4.7 - OnGUI prevent click/touch through 0 Answers

How do i change the GUI.Box font size and box size ? 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