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 kievar1983 · Apr 18, 2012 at 03:15 PM · guibutton

Gui question with android device

I am working on the gui interface for my game.

my game has a terrain of 1000X1000 so you will have to scroll to view the entire terrain.

on the terrain in certain areas there are buttons to make strong holds.

my question is this. When programming the gui, is the placement of buttons relative to screen size or camera location?

basically i want to know if i plan on moving the camera will the buttons move as well or do i need to update their positions?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Lttldude · Apr 18, 2012 at 03:51 PM

Using GUI. or GUILayout. will be based on the screen size not the camera location since it's all rendered on the GUI Layer of your camera. You should not need to update their positions. Just make the GUI Buttons positions fixed or relative to the screen width/screen height.

 var sW : float;
 var sH : float;

 //Tip:  when position GUI buttons and stuff, use an extra float variable like this
 //then just put the variable into a place where you would normally have to play around
 //with the numbers, then when you run it in Play mode, just change this value
 var x0 : float;

 function OnGUI()
 {
   sW = Screen.Width; //just makes it easier to reference
   sH = Screen.Height;
 
   //relative to screen size
   if(GUI.Button(Rect(sW*.1, sH*.05, sW*.1, sH*.1), "Button Based on Screen Size"))
   {
     //do stuff
   }
   //fixed
   if(GUI.Button(Rect(10, 5, 50, 5), "Fixed Button"))
   {
     //do stuff
   }
       //Dynamic button, change the starting x position based on the value you can change in the inspector, sometimes it's best to use multiple variables for all elements of the Rect (x1, x2, x3);
      if(GUI.Button(Rect(sW*x0, 5, 50, 5), "Dynamic Button"))
      {
        //do stuff
      }
 }

Hope this kinda helps. Good Luck.

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 kievar1983 · Apr 18, 2012 at 03:57 PM 0
Share

So would it be possible to add a button outside of the initial screen size and scroll the camera to it's location or should i use game objects?

avatar image Lttldude · Apr 18, 2012 at 09:57 PM 0
Share

No. You can't move the camera to see the GUI elements, they need to be moved. You could just change the GUI element's position in runtime to move into view. I use iTween for that, it's perfect.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Bigger size button help 2 Answers

c# Quit button wont quit game 1 Answer

How do i cal second question in a window? 1 Answer

Changing screen resolution with GUI Buttons 0 Answers

Unity 4.6 GUIUtility.hotControl 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