I'm working on a GUI that doesn't use Untiy's GUI system. Instead, it's composed of objects rendered by a second camera. How do I make these objects resolution independent? I gave it a shot and came up with this code:
static public Vector3 GUIPosition(float x, float y) {
GameObject GUICamObject = GameObject.FindWithTag("GUICam");
Camera GUICamera = GUICamObject.GetComponent<Camera>();
Vector3 pos = GUICamera.ViewportToWorldPoint(new Vector3((x)/100,-(y-100)/100,9));
return pos;
}
static public void Element(GameObject button, float x, float y) {
Vector3 buttonPosition = GUIPosition(x, y);
button.transform.position = buttonPosition;
}
But it doesn't do the trick; on higher resolutions, object positions tend to distort anyways. I'm obviously going about it wrong; what's the "right" way to make an object resolution independent?