I have a 3D HUD set up using some 3D models and an Orthographic Camera set to render as a regular 3D HUD should. The big problem here is whenever I change the screen size, the Camera’s view scales to scale the view of the game and it leaves behind the 3D HUD causing it to appear off-screen/too far inward. Is there any way to move the 3D HUD to keep it in the upper-left of the Camera view regardless of the Camera View’s size?
The way I handled this, is by using a script to control button adjustments (to match screens of any size on android, but you could apply it here as well) and I would get the corners and areas of the screen (to position buttons based on where they are) like this:
bottomLeft = Camera.main.ViewportToWorldPoint(new Vector2(0, 0));
bottomRight = Camera.main.ViewportToWorldPoint(new Vector3(1, 0));
topRight = Camera.main.ViewportToWorldPoint(new Vector3(1, 1));
bottomMiddle = Camera.main.ViewportToWorldPoint(new Vector3(0.5f, 0));
And I would take a buttons position and relocate it based on where the camera was like this:
ThrustButton.transform.position = new Vector3((bottomLeft.x + 1), -1.25f, 5);
or:
PauseButton.transform.position = new Vector3((topRight.x - 1.5f), (topRight.y - 1.25f), 5);
and this way I could forget about what screen size were using, and just decide how far from the corners to place buttons…
and as well I would scale the buttons based on this, something like:
if(Screen.width >= 800)
{
fullSize = true;
//Debug.Log("FullSize scale");
buttonScale = 0.3f;
}
if(!fullSize && Screen.width >= 480)
{
midSize = true;
//Debug.Log("MidSize scale");
buttonScale = 0.275f;
}
but this probably won’t work changing it at runtime, as I set these values from the get go. Good luck!