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 /
This question was closed Oct 16, 2011 at 11:32 AM by DavidDebnar for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by DavidDebnar · Oct 14, 2011 at 05:59 PM · guitexturesmenusliding

Easy way to center GUI Textures on a path?

Hey guys! I am making a menu that will have a vertical bar, that will be smaller at the top and wider at the bottom, on the right and I want my GUI Textures to slide along it. BUT. I can make them slide, but I ran into a problem of how to center them at the path. Lets say I have 5 buttons, the middle will be centered and the 2 on the bottom and 2 on the top will just be above it. But what about 4 elements?

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 DaveA · Oct 14, 2011 at 07:23 PM 0
Share

Do you mean you want all buttons to be center-aligned when stacked vertically?

avatar image DavidDebnar · Oct 14, 2011 at 08:49 PM 0
Share

Yeah, exactly. I have the moving script done. I just divide the vertical position and asign it to the horizontal one. But I just can't find a way of centering it. Or. I think I just found one while writing. I will just make a var offset and it will offset the whole group of menu buttons from the center of the screen.

1 Reply

  • Sort: 
avatar image
1

Answer by jahroy · Oct 14, 2011 at 09:57 PM

You can calculate the vertical starting point like this:

  • calculate the height of n buttons (number of buttons x button height)
  • subtract height of all buttons from height of vertical bar
  • divide this number by 2

Take the result and start your first button that many pixels from the top.

var sliderRectangle : Rect; var buttonRect : Rect; var buttonHeight : int; var buttonCount : int;

function OnGUI () { var totalButtonHeight : int = buttonCount * buttonHeight;

 var startY = sliderRectangle.y;

 startY += ( sliderRectangle.height - totalButtonHeight ) / 2;

 for ( var i = 0; i < buttonCount; i ++ ) {

     buttonRect.y = startY + ( i * buttonHeight );

     if ( GUI.Button(buttonRect, "I am button " + i) ) {
       print("button " + i + " has been pressed);
     }    
 }

}

Not sure if this will work with your non-rectangle slider...

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

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to use options in the Dropdown menu UI? 2 Answers

How can I make the in-game menu remains unchange while changing scenes? 3 Answers

Annoying warning with GUI, quick fix? 2 Answers

Web player screen resolution GUI placement 1 Answer

Simple Menu(understanding GUI) 2 Answers


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