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
1
Question by Nerull22 · Dec 08, 2011 at 05:24 AM · guitexturesguilayoutspacing

GUILayout: Placing images on top of each other

So what I'm trying to do is create 4 Textures overlap each other, so they have the same x and y position as well share a height and width. But I'm using GUILayout for screen resizing and placement issues that GUI just wasn't solving. Here is a snippet of code...

 GUILayout.BeginVertical();
 
 GUILayout.Box(circleImageOne);
 GUILayout.Box(circleImageTwo);
 GUILayout.Box(circleImageThree);
 GUILayout.Box(circleImageFour);
 
 GUILayout.EndVertical();

So those Boxes I want to be overlapping each other in the same position on the screen. But I want to be able to place those boxes in a position on the screen using the GUILayout. I'm hoping for anyone that can give me some good alternatives, but please no one responding with telling me to switch over to GUI.DrawTexture. I know that I can do it with that, but I get sizing and spacing issues with the screen resizing itself if I do that.

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
7
Best Answer

Answer by AzulValium · Feb 28, 2012 at 01:40 AM

I know this is an old thread, but you can use GUILayoutUtility.GetLastRect().

 GUILayout.BeginVertical();
 {
     GUILayout.Box(circleImageOne);
     GUI.Box( GUILayoutUtility.GetLastRect(), circleImageTwo);
     GUI.Box( GUILayoutUtility.GetLastRect(),circleImageThree);
     GUI.Box( GUILayoutUtility.GetLastRect(),circleImageFour);
 }
 GUILayout.EndVertical();


Comment
Add comment · Show 5 · 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 mikeschuld · Sep 21, 2013 at 04:49 PM 0
Share

You sir, are my hero. I would upvote this answer but I don't have enough rep yet.

avatar image Lohoris2 · Mar 31, 2014 at 12:12 PM 0
Share

@mikeschuld upvoted for you

avatar image 4crash · Sep 19, 2014 at 08:44 AM 0
Share

Thanks, your example helps me.

avatar image TheDemiurge · Mar 02, 2015 at 11:00 AM 0
Share

Have an upvote, good sir/madam. You've saved me from a considerable time futzing around with trying to negatively-space an element.

avatar image AzulValium · Mar 04, 2015 at 12:31 AM 0
Share

Well thank you very much, this was so long time ago I can believe is still useful ! haha

avatar image
0

Answer by Justin Warner · Dec 08, 2011 at 02:37 PM

As no one has posted yet, I'll just add my two cents. I don't see why you need the GUILayout if you want them stacked... I think it'd be more ideal if you were to use the normal GUI.DrawTexture, stack them that way, and find work arounds to work with different resizes... GUILayout is for automatic layouting, not for putting things where you want them to be... Whether you just make the location the Screen.width/2 and Screen.height/2 or make the location simple 0,0 and then change the sizes to change with the Screen.width/Screen.height.

I just can't see resizing being such an issue unless you're making your screen small as no other... A general rule (In my opinion) is if it works in the Web View, you're fine. That's the smallest anyone will be going unless you're developing for Android/iOS, which you could be, in that case, I'd still suggest finding a work around hah. But yeah. Good luck! (Look around the API/search Google, I'm sure someone has had this problem lol).

Comment
Add comment · Show 4 · 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 Nerull22 · Dec 09, 2011 at 02:53 AM 0
Share

Well I'm no exactly positive about this, but it's going to be a standalone application first. And I'm trying to compensate for the user being a dick when it's in windowed mode, and finding a way to break the game, and then bitching about it. What I like about GUILayout is that if you just supply a $$anonymous$$ and max of the images, then it will resize the images and their spacing with one another while keeping the ratio of the images, without having to do a lot of math and adding to the complexity of the code.

So that's why I was hoping to do it with GUILayout and not GUI. But looks like I'm going to have to do just that one part in GUI over top GUILayout. And that makes me sad.

avatar image Justin Warner · Dec 09, 2011 at 03:43 AM 0
Share

Well, could check every one in a while if the screen was resized, if so, put a registry key in to disable running the game, shut it off, then when he restarts it, give a warning that if it's done again, that he won't be able to play again... Dick move, but works too ;).

avatar image Nerull22 · Dec 09, 2011 at 08:38 PM 0
Share

Hahaha, I want people to keep playing my game though. :P I'll figure something out. Thanks for the options and opinions though.

avatar image Justin Warner · Dec 11, 2011 at 02:34 PM 0
Share

http://answers.unity3d.com/questions/21550/automatic-screen-resize.html Should work.

avatar image
0

Answer by ks13 · Dec 10, 2011 at 03:44 PM

Hi, i think you can make the window no-resizable...not 100% sure though.

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 Nerull22 · Dec 11, 2011 at 07:23 AM 0
Share

Now that I think I may be interested in. I'll have to look more into that, thanks for the suggestion.

avatar image Nerull22 · Dec 11, 2011 at 07:57 AM 0
Share

If anyone knows how to make it so that the player can't resize the window, then I'm very interested in this. Thanks for any info, I'm still researching trying to find out how, but let me know.

avatar image ks13 · Dec 11, 2011 at 07:48 PM 0
Share

Ok, sorry, this is my misunderstanding. Since i'm learning C# at same time as using Unity 3D, i mixed resizing mode in C# and GUI.Window in Unity. But, knowing that Unity allows native language imported scripts, you should be able to make a script using this C# property and make the window not unresizable. Here's the link : Windows Class

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

7 People are following this question.

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

Related Questions

GUILayout.BeginScrollView how to create new row? 0 Answers

How do I prevent "Argument Exception: Getting control 1's position in a group with only 1 controls when doing repaint" in OnGUI function of my CustomPropertyDrawer? 2 Answers

Styling an individual button in SelectionGrid 0 Answers

Correct usage of GUILayout.BeginVertical 1 Answer

Using Grayscale Textures For Transparency 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