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 MrRstar · Mar 09, 2011 at 09:13 PM · guibuttonarraybce0044

Trying to get an array to make working buttons. [Script Update]

Ok, so i have this array that makes some GUI buttons and adds the right text to them. my problem is that i don't know how to get the functionality behind them using another array. here is what i have working and the beginning of what i thought would work:

var theButtonNameArray = new Array ("Start", "Resume", "Options"); var theButtonFunctionAction = new Array ("Level1", "Level1", "OptionsScreen");

 function OnGUI () {
 // Make a text field that modifies stringToEdit.        
     for (i = 0; i < theButtonNameArray.length; i++){
             if (GUI.Button (Rect ((Screen.width*.5)-(theButtonPositionWidth*.5), (Screen.height*.5)-(theButtonPositionHeight+theButtonSpace)*(i*3), theButtonWidth, theButtonHeight), theButtonNameArray[i] + theButtonFunctionAction[i]));
                 {
                     Application.LoadLevel(theButtonFunctionAction);
                     /*print("Loading Level!");*/
                 }

         }
 }

this should be correct right? i'm still getting an error on the Application.LoadLevel or the print line saying: BCE0044: expecting :, found ';'.

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 MrRstar · Mar 21, 2011 at 07:30 PM 0
Share

FIXED IT! i'm such a noob. i had a ";" on the end of my if statement.

avatar image MrRstar · Apr 05, 2011 at 05:54 PM 0
Share

i've found out that using an enum ins$$anonymous$$d of an array would work better. with the array it wouldn't update the counters, but the enum will.

2 Replies

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

Answer by by0log1c · Mar 09, 2011 at 10:45 PM

Ahh, I've been trying to do something kind-of similar lately....actually not that much but oh well, I see what you're trying to obtain. I'm sure there's a 'clean'er way to do it, by storing 'function call'(is that what Deleguates are for???) or something.

An alternative is to store numerical value, instead of the methods themselves. Then switch() the lastButtonValue and call the desired functions.

OR - not recommended for obscure reasons, yet that could work: store the functions name as Strings in the second array then use eval().

var buttonNames = new Array("myButton1","myButton2","myButton3"); var buttonValues = new Array("myFunc1","myFunc2","myFunc3");

for(i=0;i<buttonNames.length;i++){ if(/userPressButton[i]/){ eval(buttonValues[i]+"();"); } }

function myFunc1(){//user clicked myButton1; } function myFunc2(){//user clicked myButton2; } function myFunc3(){//user clicked myButton3; }

While purely theoretical, I guess this should/could works and create a button for every buttonNames and once clicked. eval() should transform the Strings+() from the array into:

myFunc[i]();
Comment
Add comment · 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
0

Answer by DaveA · Mar 09, 2011 at 10:06 PM

Try these: GUI Toolbar: http://unity3d.com/support/documentation/ScriptReference/GUI.Toolbar.html GUI Grouping: http://unity3d.com/support/documentation/ScriptReference/GUI.BeginGroup.html GUI Layout has similar things, including a grid: http://unity3d.com/support/documentation/ScriptReference/GUILayout.SelectionGrid.html

And there's probably other ways of doing it too.

Comment
Add comment · 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

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

No one has followed this question yet.

Related Questions

sort gui button 0 Answers

changing GUI Button text with a string array 2 Answers

Create GUI based on an array 2 Answers

Click on a button that is created post start. 0 Answers

Unity Hangs/Crash when remove GUI Button. 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