Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed UI scaling bug for different aspect ratios #530

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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.