Build is changing GUI positions

I'm working on a tower defense game, where you can see a tower's radius as a guiTexture around the tower, while it's about to be placed on the map and while OnMouseOver the tower. This works perfectly in playmode with the offsets I've plotted in to place the radius correctly. However, once I build the project, the radius' position is completly off as if I didn't offset it both when the tower is about to be placed, and when OnMouseOver the tower.

Here is the code for the radius positioned on the tower:

`//Set position for radius and instantiate it. The variable "radius" holds the radius guiTexture.

position = new Vector3(transform.position.x + xOffSet, transform.position.y, transform.position.z + zOffSet);

worldPos = Camera.main.WorldToViewportPoint(position);

radiusClone = (GUITexture)Instantiate(radius, worldPos, transform.rotation);`

Here is the code for the radius positioned on the mouse before placing the tower on the map:

// place radius gui texture on mouse position by translating mouse position coordinates to normalized screen coordinates. The "TrooperRadius" guiTexture is found in the scene and moved to the mouse position.

trooperRadius = GameObject.Find("TrooperRadius");

trooperRadius.transform.position = new Vector3((Input.mousePosition.x + xOffSet) / Screen.width, (Input.mousePosition.y + zOffSet) / Screen.height, 0);

I also have an upgraded version of the radius for when the player upgrades the tower, which holds the same code as seen above just without the offsets, since the upgraded radius is a scaled version of the normal radius, and by coincidence the upgraded radius is positioned perfectly without offsets. However, there are no problems with the upgraded radius in the build, as it is positioned perfectly. There are only problems with the normal radius with offsets.

Your help is highly appreciated

GUITextures behave somewhat unintuitive, concerning their transform settings.

Generally, there are two possibilities:

1) Have the GUITexture always keep the same pixel size, independent of screen resolution. For this, you need to set transform.localScale to Vector3.zero. The actual size of the GUITexture is then given via pixelInset: pixelInset.width and pixelInset.height determine the size in pixels. Note these values scale relative to the lower left corner of the GUITexture, so to center that offset, you usually want to set pixelInset.x=-pixelInset.width/2 and pixelInset.y=-pixelInset.height/2 (or written differently, pixelInset=Rect(-mytexture.width/2,-mytexture.height/2,mytexture.width,mytexture.height)

2) Have the GUITexture always keep the same relative screen space, i.e. it scales with screen resolution. For this, you need to set x and y of transform.localScale to your desired size. However, you need to reset pixelInset to Rect(0,0,0,0) in this case, otherwise your scaling and positinoing will be skewed. Note, x and y are given in normalized viewport space, so x=1 and y=1 will have the GUITexture always exactly fill the whole screen, independend of screen size and aspect ratio. So to display the GUITexture undistorted, you need to compensate both for the texture aspect ratio, and the (inverse) screen aspect ratio. For example, for a 250x100 (=aspect ratio 2.5) texture that you want to cover 50% of a screen height of 1024x768 (=aspect ratio 1.33333), you would need to set the localScale to x=0.5/1.333333*2.5, and y=0.5

If that doesn't help solving your problem, we would need some additional info, for example: Is the positioning in the editor always correct, even when you change the size/resolution of your Game window, or change its aspect ratio (via the pulldown menu in the upper left corner of the Game window? Is the positioning in the standalone build always wrong "the same way", even if you choose different screen resolutions or aspect ratios in the Screen Resolution Dialog?