- Home /
Discrepancy Between Editor and Build World Transform Positions
I'll keep this short and sweet. I'm using 3D cubes as targeting pippers, and GUI labels for range. It works very well in the editor, the top picture. In the build, things are different.
I'm using the following code to position the red cube targeting pippers:
enemyPos = camera.WorldToViewportPoint(WorldObjects.enemyList[i].transform.position);
...
pippers[i].transform.localPosition = Vector3(Mathf.Clamp(enemyPos.x -.5, -.55, .55), Mathf.Clamp(enemyPos.y -.5, -.55, .55), 1.0);
The numbers in the Clamp are pretty strange... I tried modifying them, but it doesn't really work with any other numbers. iirc, I got them by printing the enemyPos variables, and deciding upon an acceptable range.
And this code is for the labels: (in the update function) labelPos[i] = camera.WorldToScreenPoint(pippers[i].position);
(in the OnGUI function) GUI.Label(Rect(labelPos[i].x + 20, Screen.width - labelPos[i].y - 10, 100, 30), Mathf.Round(Mathf.Abs(enemyDistances[i].z)) + "m");
Illustration:
I was going to use images, but apparently new users aren't allowed to use those. Sigh. Also, only one link is allowed. So, replace the end of that url, the file, editor-good.png with build-bad.png
TIA for reading, and TIA++ for helping. :)
Answer by Jaap Kreijkamp · Feb 08, 2010 at 11:50 PM
Don't you want Screen.height
instead of Screen.width
in the GUI.Label
code?
Well, gee. Sometimes stupid mistakes are made! The label 'discrepancy' came from the different aspect ratios between my editor window and the build window. Of course getting the height / width mismatched would cause this problem... :I I suspect a similar aspect ratio issue is the cause of the pipper problem. At any rate, thanks, man!!