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 Dashin · Jun 05, 2014 at 05:56 PM · buttonarrayarraysbuttonsfor

Creating Buttons from a Button created from an Array

Hi!

This makes no sense (At least for me! haha) The question is, I have a Listt of button I created with an array,everything is ok 'til here. I want each of those buttons to create more buttons from another array (I have an array called Section with all sections, and it has Name and Subsections, which is another Array with all subsections, this is what I want to show) The problem is, it works if I can show the subsections with a Debug.Log, and the button is working obviously, I can also hide the GUI or whatever, but not create any button!! and that's what I need!, here is the Script.

 var Side : Texture2D;
 var Up : Texture2D;
 var customGuiStyle : GUIStyle;
 var AllSections : Section[];
 
 function OnGUI(){
     GUI.DrawTexture(Rect(0,75,200,725),Side);
     GUI.DrawTexture(Rect(0,0,480,75),Up);
     for (var i=0;i<TodasSecciones.length;i++){
         if(GUI.Button(Rect(0,75+(i*50),200,50),""+AllSections[i].Name, customGuiStyle)){
 
         //This is working
             Debug.Log("Hi");
 
         //But this is not
                         if(GUI.Button(Rect(200,75,200,50),"Hi", customGuiStyle)){}        
 
         for (var j=0;j<AllSections[i].Subsections.Length;j++){
              //this is working too
              Debug.Log(AllSections[i].Subsections[j].Title);
     
              //but this is not
              if(GUI.Button(Rect(200,75+(j*50),200,50),""+AllSections[i].Subsections[j].Title, customGuiStyle)){
                     }
                 }
         }
     }
 
 }


Help! Thank you!!! :)

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
3

Answer by NoseKills · Jun 05, 2014 at 06:15 PM

GUI.Button() returns true only once when you click the button. Thats why you only get one output from Debug.Log("Hi"); for one press. That means also the second loop gets executed only that one time. You won't necessarily even see the second buttons flash on the screen because OnGUI() is executed more often than the screen is rendered.

You have to make a state machine where the first button changes a variable, and based on that variable a second loop draws the buttons from the second array every time OnGUI() happens.

 #pragma strict
 var Side : Texture2D;
 var Up : Texture2D;
 var customGuiStyle : GUIStyle;
 var AllSections : Section[];
 
 var category : int = -1;
 
 function OnGUI()
 {
     GUI.DrawTexture(Rect(0,75,200,725),Side);
     GUI.DrawTexture(Rect(0,0,480,75),Up);
 
     for (var i=0;i<TodasSecciones.length;i++)
     {
         if(GUI.Button(Rect(0,75+(i*50),200,50),""+AllSections[i].Name, customGuiStyle))
         {
             category = i;
         }
     }
 
     if (category >= 0)
     {
         for (var j=0;j<AllSections[category].Subsections.Length;j++)
         {
             //this is working too
             Debug.Log(AllSections[category].Subsections[j].Title);
 
             //but this is not
             if(GUI.Button(Rect(200,75+(j*50),200,50),""+AllSections[category].Subsections[j].Title, customGuiStyle))
             {
             }
         }
     }
 }
Comment
Add comment · Show 2 · 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 Dashin · Jun 17, 2014 at 02:49 PM 1
Share

Thank you!! I cant vote positive because I dont have 15 reputation :( srry... But thank you though!!

avatar image NoseKills · Jun 17, 2014 at 09:24 PM 0
Share

I think you should be able to select this as the "answer". There should be a tick mark somewhere... next to the thumbs maybe

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

22 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Read Array Inside Array 0 Answers

How to set parents of all objects in an array? 1 Answer

Array index is out of range 1 Answer

How to return index of List element? 1 Answer

How many audio clip arrays are supported? 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