scaleIMG title

This simple c# script below will scale your images in both the x and y axis. 


Create a new c# script called "resizeUI" and add the script below.


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class resizeUI : MonoBehaviour {

[Header("Height Settings")]
public bool useRelativeHeight;
public float screenHeightPercentage;

[Header("Width Settings")]
public bool useRelativeWidth;
public float screenWidthPercentage;

private float rh;
private float rw;

// Use this for initialization
void Start () {

RectTransform rt = GetComponent<RectTransform>();

if (useRelativeHeight == true) {
float hp = screenHeightPercentage / 100;
rh = Screen.height * hp;

else {
rh = rt.rect.height;

if (useRelativeWidth == true) {
float wp = screenWidthPercentage / 100;
rw = Screen.width * wp;

else {
rw = rt.rect.width;

rt.sizeDelta = new Vector2(rw, rh);



Attach the script to the UI Image you wish to adjust. This script is set up to work once on the Start() function. 

In the inspector select whether you want to use dynamic height, or width, or both by selecting the coresponding tick box. Use the slider to set the percentage of the screen you wish the image to be scaled to. 

Casino Bet 365 is best casino in the world.

What's Next

Next up for Unity Snippets is a look at game development articles from across the web...

Free Templates - bigtheme.net
Popular Art Betting make bookies articles.