GUI overlaps on new Instantiate

hi, fairly new to unity and i am trying to create a GUI for whenever I Instantiate a gameobject. I am instantiating 3 gameobjects and have them create a gui, each one moving over 300 in the screen width arg. I use a global variable in another script to set the screenwidth position and i know that it updates by 300 every time i create a clone but the new gui is created in the same position as the last one, over top of it.

the GUI that is attached to the Prefab is

var GUIposX : int = spawner2.enemyGUIposX;
var GUIposY : int = spawner2.enemyGUIposY;

function OnGUI() {
GUI.Box (new Rect (0, 150, 50, 50), "WPs: " + WP);
GUI.Box (new Rect (0, 200, 150, 50), "waypoint #'s: " + waypointC.Length);

GUI.BeginGroup(new Rect(GUIposX, GUIposY, 300, 500));
			GUI.Box (new Rect(0, 0, 150, 50), "Enemy " + spawner2.nameInt);
			GUI.Box (new Rect(0, 50, 150, 50), "Cur WP: " + currentWP);
			GUI.Box (new Rect(0, 100, 300, 50), "Target: " + target.x + ", " + target.z + ", " + target.y);
			GUI.Box (new Rect (0, 350, 150, 50), "Magnatude: " + moveDirection.magnitude);
GUI.EndGroup();
}

not worried about the first two boxes, it is the GUI.Group that i want to keep offsetting.

the Awake updates the global variable enemyGUIpoxX which holds the number for the offset i want. +300 every time a new one is created.

function Awake(){
	spawner2.enemyGUIposX = spawner2.enemyGUIposX + 300;
}

but like i said it just draws it ontop of the first one, then the third one over both of them. I have also tried this without “(new Rect just (Rect” with the same result.

is this the wrong way to add a new gui, is there a better way. Thanks for any help.

If you use Debug.Log() to display the values of GUIposX and GUIposY right before the GUI is drawn, what does it say? Are they the expected values, or do you get the same values each time, regardless of how many objects have been instantiated?

Did the Debug.Log, it always comes up 0 for both on every Instantiate.

Deleted the GUIposY since it doesn’t need to change, and put the GUIposX in the Awake function, and deleted the +300 so Awake went from:

function Awake(){
   spawner2.enemyGUIposX = spawner2.enemyGUIposX + 300;
}

to

function Awake(){
   GUIposX = spawner2.enemyGUIposX;

and set the value of enemyGUIposX just before the object is instantiated in the spawner2.js. The values now return correctly so hopeful it is solved. Do you think this was the correct fix to it? If it was thanks so much for the spark to lead me in the right direction. 3 hours of ramming my head into the wall was taking its toll.

I didn’t really follow how you had things set up initially, so I couldn’t really say. However, based on what you described, it did sound like your variables were somehow set up incorrectly (in that you weren’t actually accessing the variables that you thought you were accessing).