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 mrnee · Nov 22, 2012 at 09:49 PM · javascriptguilabel

GUILabel doesn't show up

 function OnGUI (){
     if (showGameButtons){
         // Player ends turn by banking points earned in this turn
         if (GUI.Button (Rect(10,40,100,30),"Bank")){
             if (GameObject.Find("player(Clone)"+activePlayer).GetComponent("PlayerAttributes").score==0){
                 if (PreScore.guiScore>=1000){
                     GameObject.Find("player(Clone)"+activePlayer).GetComponent("PlayerAttributes").score += PreScore.guiScore;
                     endTurn();
                 }else{
                     print("shikaka");
                     GUI.Label(new Rect((Screen.width-500)/2,Screen.height/2-15, 520, 22), "You need atleast 1000 points to open the game!",alertStyle);
                 }
             }
             if (GameObject.Find("player(Clone)"+activePlayer).GetComponent("PlayerAttributes").score>0){
                 if (PreScore.guiScore>=350){
                     GameObject.Find("player(Clone)"+activePlayer).GetComponent("PlayerAttributes").score += PreScore.guiScore;
                     endTurn();
                 }else{
                     GUI.Label(new Rect((Screen.width-500)/2,Screen.height/2-15, 520, 22), "You need atleats 350 point to bank!",alertStyle);
                 }
             }
         }
         if (GUI.Button (Rect(130,40,100,30), "Keep")) {
             // to press this button preScore must be bigger than 0;
             if (PreScore.preScore>0){
                 PreScore.turnScore += PreScore.preScore;
                 PreScore.preScore = 0;
                 gameObject.GetComponent("PreScore").reset = true;
                 gameObject.GetComponent("Roll").enabled = true;
                 print(PreScore.preScore);
                 KillDice();
                 
             }else{
             // pazinojums, ka jaatzime vismaz viens kaulins
             }
         }
     }
     if (!showGameButtons){
         GUI.Label(new Rect((Screen.width-500)/2,Screen.height/2-15, 520, 22), "You can't score anything with these dice!",alertStyle);
         if (GUI.Button (Rect(((Screen.width - 120) / 2)+10, Screen.height/2+25,100,30),"End Turn")){
             endTurn();
         }
     }
 }

The problem is that it won't show alert label "You need atleast 1000 points to open the game!". Any ideas why? it prints "shikaka" to console :S

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
1
Best Answer

Answer by whydoidoit · Nov 22, 2012 at 09:57 PM

It would only show it while the button was held down. You should initialize some time when that message is triggered and then show it while the time is less than that target:

 var message1Time : float;
 var message2Time : float;
 
 function OnGUI (){
     if (showGameButtons){
        // Player ends turn by banking points earned in this turn
        if (GUI.Button (Rect(10,40,100,30),"Bank")){
          if (GameObject.Find("player(Clone)"+activePlayer).GetComponent("PlayerAttributes").score==0){
           if (PreScore.guiScore>=1000){
               GameObject.Find("player(Clone)"+activePlayer).GetComponent("PlayerAttributes").score += PreScore.guiScore;
               endTurn();
           }else{
               print("shikaka");
               message1Time = Time.time + 4;
           }
          }
          if (GameObject.Find("player(Clone)"+activePlayer).GetComponent("PlayerAttributes").score>0){
           if (PreScore.guiScore>=350){
               GameObject.Find("player(Clone)"+activePlayer).GetComponent("PlayerAttributes").score += PreScore.guiScore;
               endTurn();
           }else{
               message2Time = Time.time + 4;
           }
          }
        }
        if(message1Time > Time.time)
        {
               GUI.Label(new Rect((Screen.width-500)/2,Screen.height/2-15, 520, 22), "You need atleast 1000 points to open the game!",alertStyle);
        }
        if(message2Time > Time.time)
        {
               GUI.Label(new Rect((Screen.width-500)/2,Screen.height/2-15, 520, 22), "You need atleats 350 point to bank!",alertStyle);
        }
        if (GUI.Button (Rect(130,40,100,30), "Keep")) {
          // to press this button preScore must be bigger than 0;
          if (PreScore.preScore>0){
           PreScore.turnScore += PreScore.preScore;
           PreScore.preScore = 0;
           gameObject.GetComponent("PreScore").reset = true;
           gameObject.GetComponent("Roll").enabled = true;
           print(PreScore.preScore);
           KillDice();
 
          }else{
          // pazinojums, ka jaatzime vismaz viens kaulins
          }
        }
     }
     if (!showGameButtons){
        GUI.Label(new Rect((Screen.width-500)/2,Screen.height/2-15, 520, 22), "You can't score anything with these dice!",alertStyle);
        if (GUI.Button (Rect(((Screen.width - 120) / 2)+10, Screen.height/2+25,100,30),"End Turn")){
          endTurn();
        }
     }
 }
Comment
Add comment · Show 1 · 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 mrnee · Nov 22, 2012 at 10:10 PM 0
Share

wow - thanks for help and very quick reply!

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

10 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

Related Questions

Timer Between Labels 2 Answers

[Solved]Label is not a member of GUI anymore. 1 Answer

Setting Scroll View Width GUILayout 1 Answer

How Would I Make A GUI Label Fade After A Certain Amount Of Time? 1 Answer

For Loop GUILayout.Label Problems 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