Quantcast
Channel: Questions in topic: "independent"
Viewing all articles
Browse latest Browse all 102

Making an object resolution-independent

$
0
0

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?


Viewing all articles
Browse latest Browse all 102

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>