Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions UOP1_Project/Assets/Scripts/UI/UIScaling.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,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
}
}
11 changes: 11 additions & 0 deletions UOP1_Project/Assets/Scripts/UI/UIScaling.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.