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 Craze · Feb 18, 2011 at 08:29 AM · guibuttonarraygridwindow

A few GUI related questions.

Hello, I am trying to make a grid of 4 by 4 buttons and have successfully made them appear within my game, however, I have no idea how to call other functions when they are pressed. I am using an Array to create the text images obviously, but I am having trouble figuring out how to call each one.

On a different not, if I wanted this grid of buttons to be within a window, what exactly would I need to do? Because currently I cannot stop the window from covering the grid.

Also, I would love it if the buttons in the grid would cause a function to run while they are being hovered over by the players mouse.

If anyone has any suggestions I'd really appreciate it!

Basically using this setup:

var Skin2 : GUIStyle; var GridInt : int = 0; var GridImage : Texture[];

function OnGUI(){ GridInt = GUI.SelectionGrid (Rect (200, 100, 400, 400), GridInt, GridImage, 4, Skin2); }

I cut out the rest of the script, so it wasn't overly cluttered

Thank ~Craze

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 Craze · Feb 18, 2011 at 12:41 PM 0
Share

Eck, I found the answer to the figuring out which button is clicked, but still haven't figured out how to make it like the window.. :/ lame

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Leviathan · Feb 18, 2011 at 01:40 PM

As you have probably figured out by now, your variable "GridInt" always shows the current selection of the grid.

What do you mean by the window "covering" the grid? Is the window on top of the grid instead of underneath?

What do you want to achieve if the user hovers over a button of yours? If you just want to change the color or texture of the button or its text, you best use the parameters for onHover in your variable for the GUIStyle in the inspector.

Another possiblity is to check in the update function, if the mouse is over a specific button in your grid.

To do this you can check the mousePosition with Input.mousePosition and check for each of the Rects of your buttons if it the position of the mouse is in the Rect. See here for the Scripting Reference: http://unity3d.com/support/documentation/ScriptReference/Rect.Contains.html .

There might be a better way to achieve this, but it is the first solution that came to mind for me.

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 Craze · Feb 18, 2011 at 10:57 PM 0
Share

I if I create a window that I want the grid of buttons to exist within, the window prioritizes it self over the grid and covers it. Unfortunately, I have no found a single way to by pass this unfortunate error, $$anonymous$$aybe I am just missing something. Also, thanks for that link on the Rect.Contains tip.

avatar image Craze · Feb 18, 2011 at 10:58 PM 0
Share

if* /10charnabz

avatar image Leviathan · Feb 19, 2011 at 09:48 AM 0
Share

I had a similar problem with one GUI Element covering another one. In my case, I just gathered all calls to GUI.x in one Script. The order in which you use the methods is the order the GUI elements are built with. So you just have to build your window first in that script and build the SelectionGrid afterwards. Alternatively, you can use GUI.depth, to declare a depth level for your GUI elements. I haven't tried that out yet, but someone mentioned it as an answer to a similar question of $$anonymous$$e. See the reference: http://unity3d.com/support/documentation/ScriptReference/GUI-depth.html

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

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

Add EditorUI elements when a button is pressed 0 Answers

GUI Button and Window 1 Answer

How to make a or array of GUI.Button's? 1 Answer

Easy way to make buttons in-accessible when under a pop-up window? 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