-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathUIScaling.cs
More file actions
22 lines (18 loc) · 826 Bytes
/
UIScaling.cs
File metadata and controls
22 lines (18 loc) · 826 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UIScaling : MonoBehaviour
{
// Gets the necessary canvas object
private CanvasScaler scaler;
// Gets the display's width and height in pixel size
private int width = Screen.width;
private int height = Screen.height;
private void Start()
{
scaler = GetComponent<CanvasScaler>(); // Gets the necessary component for scaling modification
scaler.referenceResolution = new Vector2(width, height); // Ensures the UI is sized according to screen pixel data
scaler.screenMatchMode = CanvasScaler.ScreenMatchMode.MatchWidthOrHeight; // Matches the UI to referenced screen size
}
}