- Home /
Paused Menu backdrop
Hey there, I have a small question, I'd like to have a semi-transparent GUI color or texture put into the game viewport when paused, sort of like in MW2, Mirror's Edge, Minecraft and lots of other games. All I need is to know how to render something like that across the entire screen (independent of screen size), instead of a single massive GUI texture, which could mess up if the resolution is higher than usual. I looked through the documentation under GUI but there isn't anything that pertains to this in particular. btw, Also I was wondering how to center a different GUItexture in the middle of the screen according to percentage instead of pixel offset. Thanks
Here's my bit of code for GUI:
function OnGUI() {
GUI.color = Color.black; //version number print, ignore this
GUI.Label (Rect (10,10,200,20), message);
GUI.color = Color(1,1,1, 0.5);
GUI.Label (Rect (9,9,200,20), message);
if (Time.timeScale == 0){ //pauses the game
//here's where I need something
}
}
Answer by GlennHeckman · May 26, 2011 at 03:30 AM
For centering an object use this:
var screenCenterX:int = Screen.width/2;
var screenCenterY:int = Screen.height/2;
var myObjectWidth:int = 300;
var myObjectHeight:int = 100;
var objX:int = (myObjectWidth/2) - screenCenterX;
var objY:int = (myObjectHeight/2) - screenCenterY;
You obviously don't have to use all of those variables, but I put them there to help point out the "elements" used in a typical centering formula.
As for a full screen cover, there are many ways. Personally, I would probably create a customStyle in my GUISkin or a local GUIStyle and set the Normal value for the Box style to a semi transparent graphic you've created in Photoshop (or a similiar app). In the Box style drop down, set the width and height checkboxes to stretch. To have it display, put this code:
var transparentScreen:GUIStyle; //this goes at the top of your script
function OnGUI()
{
GUI.Box(new Rect(0,0,Screen.width,Screen.height),"","transparentScreen");
}