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 RafaelCN · May 04, 2013 at 11:22 PM · guitexturebuttonlabel

Creating a component from a button click

Hello everyone. I've stuck in one error.. When a click in a button i want to create a component, something like a Label, or a text field. When i click in the button nothing happens. I already did the: Debug.Log("You clicked in a button"); Works fine, but nothing is created. I've tried this:

 public Texture2D[] acordingTxt = new Texture2D[10];     
 
 
 void OnGUI() {
 if(createButton(50, 50, 100, 40, buttonTxt[0])) {createLabelC(550, 400, 500, 500, acordingTxt[0]);
 GUI.Label(new Rect(550, 400, 500, 50), acordingTxt[0]); 
 Debug.Log("you've created a label");
 }
 }

the createLabelC() and the createButton() is my methods to make what GUI.Button and GUI.Label, i've tried create this Label from GUI.Button(...) but nothing happens too! Just the Debug.Log(""); appears to work.

Thank you guys.

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

Answer by robertbu · May 05, 2013 at 06:35 AM

GUI.Button() returns true only for a single frame (when the button is released). So your label is being shown for 1/60 of a second or so. Instead of GUI.Button(), use GUI.RepeatButton(). It will return true as long as the button is held down.

Comment
Add comment · Show 9 · 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 05, 2013 at 09:02 PM 0
Share

i really appreciate, thank you!

avatar image RafaelCN · May 05, 2013 at 09:24 PM 0
Share

but, have other way to do that?

avatar image robertbu · May 05, 2013 at 09:46 PM 0
Share

I don't understand. Another way to do what?

avatar image RafaelCN · May 09, 2013 at 08:30 PM 0
Share

yea, to create an element ins$$anonymous$$d of RepeatButton because i need one click and the element "has created!".

avatar image robertbu · May 09, 2013 at 09:34 PM 0
Share

Here is one way to do it. Attach to an empty game object and test, then you can integrate the concept into your code:

 public class ClickAndRepeate : $$anonymous$$onoBehaviour {
     Rect rect = new Rect(50, 50, 100, 40);
     void OnGUI() {
         
         Event e = Event.current;
         if (e.type == EventType.mouseDown && rect.Contains(e.mousePosition))
             Debug.Log ("Fire once per click");
             
         if (GUI.RepeatButton(rect, "Button")) {
             GUI.Label(new Rect(550, 400, 500, 50), "Button was pressed");
             }
         }
 }
Show more comments

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

12 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

Related Questions

Null reference exception[SOLVED] 1 Answer

GUI.Label positioning for many device resolutions 1 Answer

GUI, making main page lead into an instructions page 2 Answers

GUI button doesn't appear on Android 0 Answers

Make GUI Button's size fit texture? 2 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