Greetings!
I have built a nice UI that works well with any resolution, due to “UI Scale Mode” → “Scale With Screen Size” and Anchors.
Now I want to let the player finetune the UI Size for his taste via a slider in the options menu (like for example in Endless Space 2). But in contrary to “Constant Pixel Size” there is no global Canvas scale value in “Scale With Screen Size”.
So my question is:
How to modify the scaling of the whole UI at once per script in “Scale With Screen Size” - mode?
Thank you!
Have you tried changing the value of the reference resolution?
canvasScaler.referenceResolution = initialReferenceResolution * multiplier;
my solution:
i put all my UI in a whole wrapper to let the player scale the ui.
the slider minVal = 0, maxVal = 200 and standard is set to 100;
public RectTransform mainUi;
public Slider uiScaler;
public TextMeshProUGUI uiScaleText;
public Vector2 orgRes;
void Start()
{
orgRes = mainUi.sizeDelta;
}
void Update()
{
if(Input.GetKeyDown(KeyCode.T))
{
SetNewUiScale();
}
uiScaleText.SetText(uiScaler.value.ToString());
}
public Vector2 SetNewUiScale()
{
mainUi.sizeDelta = orgRes;
mainUi.sizeDelta = mainUi.sizeDelta / 100 * uiScaler.value;
return mainUi.sizeDelta;
}