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 MythStrott · Aug 05, 2010 at 02:24 AM · guibuttoninventoryfloat

GUI Button Position - Can it float to the top-left?

Hello,

I'm still getting used to the Unity Scripting language. However, I'm learning pretty fast now. I started writing a script for an inventory in my game. It's working quite well. But as it is right now, the buttons for each item have their own position inside the inventory. I need to get it so the buttons position is some type of "float: left". Is this possible? I have them in a GUI Group (the inventory space) so it would work if they float to the top-left of this group.

Here's the current code for one of the item buttons:

if (logs > 0){
if (GUI.Button (Rect (75,0,75,75), logs + " Logs")) {
        var otherMakingFire : MakingFire = gameObject.GetComponent(MakingFire);
        otherMakingFire.MakeCampFire ();
    }
    }

What I need to get is changing

Rect (75,0,75,75)

to something similar to

Rect (top,left,75,75)

Thanks for any help!

(If you want to see the game so you know what I'm talking about, the newest version is always available at http://www.mythstrott.webs.com/mythstrott.html)

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by MythStrott · Aug 06, 2010 at 05:24 AM

After more searching, I found this:

http://unity3d.com/support/documentation/Components/gui-Layout.html

I haven't used it yet, but it seems to be the solution. So if anybody else was having this problem, read the link :)

Thanks to the 3dDude and spree for trying.

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
avatar image
1

Answer by 3dDude · Aug 05, 2010 at 02:37 AM

in place of a pixel position you can use something like this :

var pos : Vector2;
Rect (Screen.width/pos.x,Screen.height/pos.y,75,75);

using this method it well always stay in the top left corner.

you just have to change the x and y of the pos var and it should make the gui position change

Comment
Add comment · Show 6 · 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 MythStrott · Aug 05, 2010 at 03:25 AM 0
Share

I'm not sure what I am supposed to set x and y to?

avatar image StephanK · Aug 05, 2010 at 09:19 AM 0
Share

If it's in a group the top left position in this group is just 0,0 afaik.

avatar image 3dDude · Aug 05, 2010 at 01:36 PM 0
Share

well if you set x and y to 2 then it will make the position always be in the center because if you divide something by 2 its half of it. so you can just try different values to get it into the top left corner

avatar image MythStrott · Aug 05, 2010 at 02:37 PM 0
Share

Ok, well this doesn't solve my problem. Did you read my question?

What I have is multiple buttons. Each button is an item. Sometimes the an item is active, sometimes not. I have that scripting done. But my problem is that the buttons for each item have their own position inside the inventory. I need to get it so the buttons go to the top-left position without overlapping

Thanks

avatar image 3dDude · Aug 05, 2010 at 04:29 PM 0
Share

what do you mean "overLapping"?

Show more comments
avatar image
0

Answer by Timurov · Nov 09, 2012 at 08:59 AM

Read this http://docs.unity3d.com/Documentation/Components/gui-Basics.html it might be helpful for your problem, go to the The Boxes positioned by the above example section.

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

1 Person is following this question.

avatar image

Related Questions

GUI Button to create another GUI 1 Answer

Button being pressed but an other button gets the effect. 0 Answers

GUI grid of buttons issue. 1 Answer

button wont work in GUI.BeginScrollView 0 Answers

GUI Button follow GameObject, like floating button how to on C++? 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