Creating buttons or text fields in a relative position irrespective of resolution for an interface control

ISSUE: How do I go about placing GUI or GUILayout buttons, textfields or similar in specific places on my screen regardless of screen resolution.

DETAILS: We are trying to create a user interface that will have a fixed camera (CamA) floating above an object. The object will act as if it is a screen or frame, with 3d boxes at specific positions acting as OnEvent buttons. However, I have a text field that needs to be placed at a specific location on the image overlay so that the text entry field position exactly matches or overlays the filed on the image placed onto the frame.

EXAMPLE: Login in screen, with two text entry fields, name and pwd, which have to be placed exactly over the white space area on the image being used so as to make it seem that the log in text field is actually the image and not the underlying GUILayout field.

This is a harder problem. The issue is not just making a conversion from world space to GUI space, but that you have issues about how to anchor the objects (GUIs use Rects which are anchored in the upper left corner and world space object generally use a pivot in the center), and height and width issues. The height and width of objects in world space will take different numbers of pixels depending on the screen resolution. The easiest solution is to draw the texture with GUI.DrawTexture(). That way the graphics and the text fields will be in the same space. If you need to have the graphics in world space, then the conversion can be done this way:

var pointInScreenSpace = Camera.main.WorldToScreenPoint(pointInWorldSpace);
var pointInGUISpace = Vector3(pointInScreenSpace.x, Screen.height - pointInScreenSpace.y, pointInScreenSpace.z);

You can use empty game objects to anchor the position on the world game object. You can get an approximate size by multiplying the width and height parameters in the Rects used in GUI by the ratio of the screen height you used in authoring to the ratio of the height of the current device.