To create a 3D UI, you need to have a world space UI since a normal one will not use a perspective camera, any ideas on how to either a. have it scale to fit screen sizes perfectly, or b. an alternate method for 3D UI.
The current UI I have looks nice in the editor, but once the screen size changes, it does not fit the screen nicely like the usual Overlay UI.
Solved by scaling along the X axis of the canvas to match the aspect ratio, the Y axis seems to never need changing
/// <summary>
/// Scales the current object with the aspect ratio on awake
/// </summary>
public class ScaleWithAspectRatio : MonoBehaviour {
#region PUBLIC_VARIABLES
/// <summary>
/// The aspect ratio used in design, this is the calculated ratio (ie. 16:10 = 16/10 = 1.6)
/// </summary>
[Tooltip("The aspect ratio used in design, this is the calculated ratio (ie. 16:10 = 16/10 = 1.6)")]
[SerializeField] private float designRatio = 1.6f;
#endregion // PUBLIC_VARIABLES
#region MONOBEHAVIOUR_METHODS
/// <summary>
/// Awake this component
/// </summary>
void Awake () {
float screenRatio = (float) Screen.width / (float) Screen.height;
float newXScale = transform.localScale.x / designRatio * screenRatio;
transform.localScale = new Vector3(newXScale, transform.localScale.y, transform.localScale.z);
}
#endregion // MONOBEHAVIOUR_METHODS
}
using a screen space camera canvas will use whatever camera you specify, so if its perspective it will use that.
Thanks fill, that will save me having a second camera. Problem was though when I tested the screen space camera it was scale with screen size to match the width which was affecting the scaling when changing res, switching to match height resolved the issue.