- Home /
Scale UI by Slider
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!
Answer by Hellium · Mar 13, 2021 at 04:15 PM
Have you tried changing the value of the reference resolution?
canvasScaler.referenceResolution = initialReferenceResolution * multiplier;
Answer by Kaputtccino · May 28 at 04:38 PM
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;
}
Your answer
Follow this Question
Related Questions
How to adjust scale of UI panel as to fill percentage of the screen? 0 Answers
Using Hinge Joint 2D with scaled UGUI 0 Answers
Scene loading incorrectly 1 Answer
Unity UI: Issue with 3:4 vs 9:16 resolutions 1 Answer
Button position scaling weird 1 Answer