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 GetColor · Jul 10, 2012 at 06:54 PM · guiongui

How to be specific and universal with your onGUI controls?

Perhaps my question is stated in an odd way, but I have been having really strange issues with my GUI buttons - and GUI labels as well.

First off, I may need some general help with the concept of the onGUI function. I have read the scripting reference, so I understand everything there, but I may just be doing it wrong.

When I take the time to position everything where I want it, when I make a stand alone build of my game (I sent it to a few friends for feedback) I noticed on that build the hud is not where it should be. It's slightly off. in the editor, they are placed perfectly!

And the stranger of the two issues is that literally over night my main menu buttons broke. I found out that the numbers I had for their height and width were where i set them, but now they are off screen. So despite me placing them on screen where I wanted them, and without me altering the main menu script or that scene AT ALL, a few days later, the buttons are off screen but with the same height and width I had set. (but not all of them, only half... I'm so confused!)

This is how I have been coding them in (c#):

             // Button for Playing the Game
         if (GUI.Button(new Rect(startGameWidth, startGameHeight, 125, 35), "", start_GUIStyle))
         {
             Application.LoadLevel("blipbloop_Game");
             s_GameManager.originalBlipPlayerName = tempPlayer1name;
             s_GameManager.originalBloopPlayerName = tempPlayer2name;
         }

         // Button for Controls
         if (GUI.Button(new Rect(controlsWidth, controlsHeight, 200, 35), "", controls_GUIStyle))
         {

         }


The width and height variables specific to each button are just float variables with numbers I assign to them. Should I be coding them differently? ANY help is greatly appreciated! (and I'm aware my controls button doesn't do anything when clicked, and I have images with text as the button states, so that is why the buttons themselves have a blank string in them.)

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 animusrecro · Jul 10, 2012 at 07:11 PM 0
Share

I usually multiply the screen width for the x location and x size and height for the y location. And y size so that way they will be i'm the proper place no matter what screen size they are placed on

avatar image GetColor · Jul 10, 2012 at 10:36 PM 0
Share

So what would you do specifically? $$anonymous$$y game is running at a fixed resolution, which is why I am confused that the hud elements aren't always in the same spot.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Kensei · Mar 29, 2014 at 06:05 AM

I had the same problem and I found an answer here.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Please help I don't understand what is wrong. 1 Answer

Hiding OnGUI? 1 Answer

[Solved] GUI Error? 1 Answer

Why doesn't my GUI.Label show up? 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