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 RafaelCN · May 04, 2013 at 03:40 PM · guibuttonifguilabel

creating a label from a button click

I have one button, that will check if my textfield is filled. If it's not, it will create a label for me, but isn't working. So please guys, tell me why =).

A lil bit of my code:

 contentOfTextField = createTextField(400, 200, 400, 30, contentOfTextField, 20);    
             
             if(createButton(620, 500, 100, 30, "Confirm")) {
                 if(contentOfTextField.Length == 0) {
                         createLabel(400, 100, 300, 30, "Please, put an user name!");
                     
                 }
                 else {
                     confirm = true;
                 }
             }

Thank you!

Comment
Add comment · Show 2
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 ByteSheep · May 04, 2013 at 04:01 PM 0
Share

Well this is where debugging comes in handy. Use Debug.Log() or print() to get the values returned by contentOfTextField:

 if(createButton(620, 500, 100, 30, "Confirm")) {
    Debug.Log("The text field string equals: " + contentOfTextField.ToString() + " and has " + contentOfTextField.Length + " characters.");
 }

Btw how are you creating the button and textfield?

avatar image RafaelCN · May 04, 2013 at 08:33 PM 0
Share

the creation of the button it is a method:

 public bool createButton(float left, float top, float width, float height, string content) {
         return GUI.Button(new Rect((screenX-screenX)+left, (screenY-screenY)+top, width, height), content);
     }

the same way in the textfield! I forgot of this Debug.Log :p. Thank you, i used that! He shows me the size of the textfield, but it isn't show the label that i want to create:

 if(createButton(620, 500, 100, 30, "Confirm")) {
                 if(contentOfTextField.Length == 0) {
                         createLabel(400, 100, 300, 30, "Please, put an user name!");
                         Debug.Log("The caracters of the textfield:"+contentOfTextField.Length+"");
                 }
                 else {
                     username                            = contentOfTextField;
                     confirm                                = true;
                     showContentProfile                    = false;
                     Instruments.clickedConfirm            = true;
                     Instruments.showContentInstrument    = true;
                 }
             }

1 Reply

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

Answer by FL · May 05, 2013 at 05:16 PM

Your way only display the label a single frame (or even less). Declare a global variable private var showLabel : boolean = false;. Change your code to:

 contentOfTextField = createTextField(400, 200, 400, 30, contentOfTextField, 20);
 
      if(createButton(620, 500, 100, 30, "Confirm")) {
       if(contentOfTextField.Length == 0) {
              showLabel = true;
       }
       else {
           confirm = true;
       }
      }
      if(showLabel)
          createLabel(400, 100, 300, 30, "Please, put an user name!");
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 RafaelCN · May 10, 2013 at 10:28 PM 0
Share

that's right, i follow the same logic, but i want that label just appears when the user press the button and disappear when he leave's the button, and this fits better with RepeatButton! So thank you anyway.

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

13 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

Related Questions

If button highlighted 2 Answers

A Button, A Boolean and 2 Textures. 2 Answers

Button Turns Off and On Object 1 Answer

Button then instanitates gameobject 1 Answer

How to hook up the particle system to jump animation? 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