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 ninjaboynaru · Jul 09, 2013 at 11:17 PM · javascriptguitoggle

Actually do something with GUI selection grid

How do I get a selection grid to actually to something. Like how would I clicked which button on the grid has been pressed then do something.

Here is my code so far

 var gridId : int;
     var gridRowX : int;
     var menueGrid : String[] = ["Health", "Crafting", "Melee", "Guns"];    
     
     
     
     var gridXPos : int; // temporaray;
     var gridYPos : int; // temporaray;
     var gridXSize : int;
     var gridYSize : int;
     
     
     
     function OnGUI(){
         GUI.skin = mySkin;
         if(menueActive){
             GUI.BeginGroup(Rect(xPos,yPos,500,300), mySkin.GetStyle("base"));
                 GUI.SelectionGrid(Rect(gridXPos,gridYPos,gridXSize, gridYSize),gridId, menueGrid, gridRowX,mySkin.GetStyle("grid1"));
                 
                 Debug.Log(gridId);
         
             GUI.EndGroup();
         }
     
     }
Comment
Add comment · Show 3
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 Lo0NuhtiK · Jul 09, 2013 at 11:34 PM 0
Share

example :

 public int selGridInt = 0;

 public string[] selStrings = new string[] {"Grid 1", "Grid 2", "Grid 3", "Grid 4"};
     
 void OnGUI()
 {
      selGridInt = GUILayout.SelectionGrid(selGridInt, selStrings, 2);
         
      GUILayout.Box(selStrings[selGridInt]) ;
 }
avatar image ninjaboynaru · Jul 10, 2013 at 12:57 AM 0
Share

I tried your example. selGridInt dose not change, it just stays 0

avatar image ninjaboynaru · Jul 10, 2013 at 05:36 PM 0
Share

opps, never $$anonymous$$d it dose. I just did not look carefully enough. Turns out Selection Grid returns a integer.

1 Reply

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

Answer by johnnymoha · Jul 10, 2013 at 01:28 AM

 var selGridInt : int = 0;
 var selStrings : String[] = ["Grid 1", "Grid 2", "Grid 3", "Grid 4"];
 
 function OnGUI () {
     selGridInt = GUI.SelectionGrid (Rect (25, 25, 100, 30), selGridInt, selStrings,2); 
     //selGridInt will change based on your selected box
 
    if (selGridInt==whatever){
       Debug.Log("stuff here");
    }
 }
 
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 ninjaboynaru · Jul 10, 2013 at 05:37 PM 0
Share

Thanks to the both of you. If I would have read the API more carefully I would have realized that selection grid returns an int that needs to be stored in a varible.

avatar image UNDERHILL · Jul 09, 2014 at 03:22 AM 0
Share

how can i get a different script on a different object to know which one?

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

17 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

Related Questions

Setting Scroll View Width GUILayout 1 Answer

GUI.Toggle to only send one action, not repeated 1 Answer

Trouble getting GUI phone to open/close 1 Answer

3 sets of button activations GUI 1 Answer

GUI.Button toggling object visibility. 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