Center GUI Window to screen Middle?

I actually have two questions here and I’m not sure if I should trouble people too much with asking twice so I’ll post both my problems with this script here:

1- How can I make this so it fits in the middle of the screen for all screen resolutions?
I noticed today that it fits perfectly on my screen middle when played on the stand alone player at 1680 X 1050 But NOT centered correctly if viewed at any other screen resolution???

2- I am having extreme difficulty trying to figure out and find any information on how to freeze my background when my pop up window is activated. So far all I’ve managed to do is stop the fps player from being able to walk around and limited the mouselook to only move horizontally so I’m still chasing my window around the screen in order to click on any of the buttons… Very frustrating.

3- I noticed that another problem I’m having with this is it seems to ignore this part of the code where I create a duplicate of this script for another T Shirt Pop Up Window and re name the “doWindow0” to “doWindow2”???

if (doWindow0) {

         obj.GetComponent(FPSInputController).enabled = false;

         GameObject.Find("Main Camera").GetComponent("MouseLook").enabled = false;

   	} 

   	

   	   if (!doWindow0) {

         obj.GetComponent(FPSInputController).enabled = true;

         GameObject.Find("Main Camera").GetComponent("MouseLook").enabled = true;

   	}

I iave no idea why it’s doing this. Perhaps there is a better way of handling these pop up windows as I need to create a hell of a lot of them??

Here is my Code I have done so far:

    var doWindow0 : boolean = false;



var aTexture : Texture;

var closeIcon : Texture2D;

var buyNowButton : Texture2D;



var obj : GameObject; // first person controller

function OnGUI () {

GUI.backgroundColor = Color.black; //Background Color of Window

GUI.contentColor = Color.yellow;   //Color of text within my Window


// Make sure we only call GUI.Window if doWindow0 is true.

if (doWindow0)

GUI.Window (0, Rect (350,250,800,500), DoMyWindow, "Suicide of T-Bear T-Shirt.");



///// Stops player from walking around while viewing the pop up window

if (doWindow0) {

             obj.GetComponent(FPSInputController).enabled = false;

             GameObject.Find("Main Camera").GetComponent("MouseLook").enabled = false;

       	} 

       	

       	   if (!doWindow0) {

             obj.GetComponent(FPSInputController).enabled = true;

             GameObject.Find("Main Camera").GetComponent("MouseLook").enabled = true;

       	}   

}

// Make the contents of the window

function DoMyWindow (windowID : int) {

//This is where I place my Product Photo @ 402 X 402 pixels in size

if(!aTexture){

Debug.LogError("Assign a Texture in the inspector.");

return;

}

GUI.DrawTexture(Rect(10,70,402,402), aTexture);

// This is where I add my descriptive product text NOTE: Be sure to include the "

" in between your lines of text
var stringToEdit : String = “The attempted suicide of T. Bear T-Shirt
Inspird by a T.V. episode of Supernatural
Comfortable, casual and loose fitting, our heavyweight t-shirt will quickly
become one of your favorites. Made from 6.0 oz, pre-shrunk 100% cotton,
it wears well on anyone. We’ve double-needle stitched the bottom and
sleeve hems for extra durability. Imported.”;

stringToEdit = GUI.TextArea(Rect(425,75,360,300), stringToEdit, 500);

//This is my Web Link Button

if (GUI.Button( Rect(610,430,179,60), buyNowButton)) {

Application.OpenURL("http://www.zazzle.com/t_bear_suicide_t_shirt-235455214631112735");

}
if (GUI.Button (Rect (752,20,30,30), closeIcon))

doWindow0 = false;
}

//This is my Close GUI Window Button

function OnMouseDown()

{

doWindow0 = true;
}

Here's a simple function that returns a centered rectangle.

The input is a rectangle. The output is the input rectangle centered.

Below is an example of how you might use it in an OnGUI function...

/* return the centered version of someRect */

function centerRectangle ( someRect : Rect ) : Rect
{
    someRect.x = ( Screen.width  - someRect.width ) / 2;
    someRect.y = ( Screen.height - someRect.height ) / 2;

    return someRect;
}

/* example usage */

function OnGUI ()
{
    var theRect : Rect    =  Rect(350, 250, 800, 500);
    var theMsg  : String  =  "Happy Dancing Bear T-Shirt";
    var winId   : int     =  0;

    /* center the rectangle */

    var centeredRect : Rect = centerRectangle(theRect);

    GUI.Window (winId, centeredRect, DoMyWindow, theMsg);
}

For question 2...

You can just place the code that draws your window inside of an if statement like this:

if ( isWindowVisible ) {
    GUI.Window(theId, theRect, theFunction, theTitle);
}

Elsewhere you can just ignore certain code if isWindowVisible is true.

It looks like you're already doing that within the local script.

You probably just have to make another script do the same thing, which will probably involve getting two scripts communicate with each other... Luckilly that's one of the most covered topics on this site.

There are over one bazillion questions about that...

There's also some nifty documentation.

It’s because you are using absolute coordinates in your window Rect. To have it calculate based on the actual screen size use:

GUI.Window (0, Rect (Screen.width - 400, Screen.height - 250,800,500), DoMyWindow, "Suicide of T-Bear T-Shirt.");

The first two parameters for the Rect constructor are the screen width minus half your window width and the screen height minus half your window height (for reference if you use a different size window at some point).

I hope that helps!