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 ina · Jan 12, 2011 at 06:45 AM · guiscreenguilayoutscreenspaceselectiongrid

Find position of SelectionGrid element clicked

How do you find the screenspace position of a SelectionGrid element that is clicked?

Comment
Add comment · Show 1
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 HHameline · Jun 20, 2011 at 02:53 PM 0
Share

I would like to know the answer to this question too :/ any hits yet?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by ckfinite · Jun 20, 2011 at 04:01 PM

It's pretty simple. You just feed the int you get back from the function into the string array you give to the function, like this:

 var selGridInt : int = 0;
 var selStrings : String[] = ["Grid 1", "Grid 2", "Grid 3", "Grid 4"];
     
     function OnGUI()
     {
        selGridInt = GUI.SelectionGrid (Rect (25, 25, 100, 100), selGridInt, selStrings, 2);
        Debug.Log(selStrings[selGridInt]);
     }
Comment
Add comment · Show 3 · 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 HHameline · Jun 20, 2011 at 04:05 PM 0
Share

Sorry What I meant and what I think ina meant was the actual rect position that the selected button in the grid is at. Not the position of the grid itself or the index of of the selected option. Sorry for any confusion.

avatar image ckfinite · Jun 20, 2011 at 04:08 PM 0
Share

Well, you could divide the number of elements by the width of buttons to get the number of rows, then partition the original rect into that many rows. Then, if the partitioned rects are in the same order as the original setup, you can just feed the index into that. I will give sample code in a bit.

avatar image HHameline · Jun 20, 2011 at 04:12 PM 0
Share

Ok, that's what I have happening now, I'm just going to be making a lot of the grids over the next few days and I was wondering if there was a nice built in way to do it that I hadn't found. I'll just keep my script nice and dynamic :P thanks for the help

avatar image
0

Answer by BerggreenDK · Aug 02, 2011 at 10:17 PM

If you have a list of eg. buttons inside your grid, I would take the selection-value from the Grid and multiply it with the pixelheight of the button-style. This might be 25 pixels or something.

Would that work or are your content of different heights?

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Aligning an overlay to existing GUI elements 0 Answers

GUISkin or otherwise - Once clicked, button stays same color 1 Answer

Styling an individual button in SelectionGrid 0 Answers

know GUILayout current screen position 2 Answers

Staggering buttons with GUI.SelectionGrid 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