Before updating to Windows 10 you may need to return your Pro license. More information here

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...


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.

more ▼

asked Dec 08, 2011 at 05:24 AM

avatar image

245 11 11 18

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

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

     GUI.Box( GUILayoutUtility.GetLastRect(), circleImageTwo);
     GUI.Box( GUILayoutUtility.GetLastRect(),circleImageThree);
     GUI.Box( GUILayoutUtility.GetLastRect(),circleImageFour);

more ▼

answered Feb 28, 2012 at 01:40 AM

avatar image

155 1 5 6

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

Sep 21, 2013 at 04:49 PM mikeschuld

@mikeschuld upvoted for you

Mar 31, 2014 at 12:12 PM Lohoris2

Thanks, your example helps me.

Sep 19, 2014 at 08:44 AM 4crash

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

Mar 02 at 11:00 AM TheDemiurge

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

Mar 04 at 12:31 AM AzulValium
(comments are locked)
10|3000 characters needed characters left

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).

more ▼

answered Dec 08, 2011 at 02:37 PM

avatar image

Justin Warner
6.8k 45 55 108

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 min 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.

Dec 09, 2011 at 02:53 AM Nerull22

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 ;).

Dec 09, 2011 at 03:43 AM Justin Warner

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

Dec 09, 2011 at 08:38 PM Nerull22
(comments are locked)
10|3000 characters needed characters left

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

more ▼

answered Dec 10, 2011 at 03:44 PM

avatar image

264 39 31 37

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

Dec 11, 2011 at 07:23 AM Nerull22

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.

Dec 11, 2011 at 07:57 AM Nerull22

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

Dec 11, 2011 at 07:48 PM ks13
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Dec 08, 2011 at 05:24 AM

Seen: 4065 times

Last Updated: Mar 04 at 12:31 AM