- Home /
GUI Texture & Main Camera Issue
I'm very new to unity, so forgive me if I don't describe things perfectly. I have been playing around with unity for a few weeks and was working on a mobile app. I created a title screen, added some buttons, created a background and then added a GUITexture with a .png file. Everything seemed to be working fine, I then tried to do some camera fading with the screenswipe.js and crossfade. I was starting to understand it; however noticed that now my GUITexture wasn't displaying anymore. I figured this was from me playing around with some scripts that i had made, and started to back track to understand how I broke it, i removed almost everything I did however my GUITexture still does not show up at all.
The only thing I have sort of figured out is when I change the object to a different specific layer that I created for the background image, it does display, though it is streteched obscenely.
I have no idea what I did to prevent my main camera from displaying GUITextures, any help would be wonderful.
Thanks!
Answer by Graham-Dunnett · Jul 10, 2013 at 08:07 PM
The positioning of GUITextures can be a bit of a nightmare. Think of the screen as being a unit square, so x and y vary from 0..1. The middle of the screen is then 0.5,0.5. The X and Y components of the transform are used to position the GUITexture. Then the X and Y components of the scale are used. I can't readily explain in words what affect they have. An X and Y scale of 1 seems to make the texture fill the screen. I'm 100% sure, if you have added a GUIComponent to your Camera, that its transform is positioning the GUITexture in some weird place. So, to avoid that, just do GameObject->Create Other->GUI Texture. You'll see this game object has a position of (0.5,0.5,0), and a scale of (0,0,1) and the texture appears in the centre of the screen.
Graham,
Thanks for your response. I think you led me in the correct direction. I ended up remaking the GUI Texture, and fixing the scale like you suggested. I added it to my background layer that I had set up, which has something to do with a culling mask on the main camera and was able to have it show up again.
I probably should make a seperate layer for all Gui Textures so I do not have it happen again.
Thanks!