How To Fit Your Game For Every Resolution In Unity

preview_player
Показать описание
In this video I explain how to use the Fit-Workground-To-Camera script to easily scale your game for all resolutions in Unity. This is needed most when developing a mobile game, but can be useful for other platforms as well.

Рекомендации по теме
Комментарии
Автор

Very cool, works for me just remove multiplication by 100, also you can make scale X: 28.125 and Y: 50

imbestpumpkin
Автор

Very good script, exactly what I was looking for :) I had to remove the multiplication by 100 but besides that works perfectly.

kecajable
Автор

your video really helped me a lot.
i followed the concept but changed it per my needs. i developed my app using a display 1080 Wx2340 H so that becomes the ratio denominator.
then if the New screen is wider than it is taller use the h_ratio otherwise use w_ratio and then scale the object you need accordingly

float w_ratio = Screen.width / 1080f;
float h_ratio = Screen.height / 2340f;
float use_ratio = w_ratio;
if (h_ratio < w_ratio) use_ratio = h_ratio;

= new Vector3(use_ratio, use_ratio, 1);

modemfish
Автор

Guys i saw a thousand videos, i asked Ai tools and everything but all of this doesnt works, now lemme tell u ITS SUPERRR SIMPLE how i figured it out. So the thing is that unity follows the values in inspector, it doesnt follows the initial values in the script. So IN UR INSPECTOR, in ur canvas screenspace -overlay OR canvas - screen space camera, first set to scale with screen size, then u just have to set the REFERENCE RESOLUTION to what u want and screen match mode to match width or height and Match accordingly 0 to 1. Thats it, that reference resolution will already be then set to whatever screen u play the game on when exported.
For example i set my reference resolution to 770x570 in inspector, now that i've exported the game i can play the game on 1920x1080 without having the game objects/ui elements change or go out of screen, they appear with perfect size and adjust appropriately.

qazisaad
Автор

Doesn't work for me :( I have sprites and raw images on scene, portrait mode, scale with screen size 1080x1920 match with width and i cant setup it properly to scale my all objects to diffrent resolution :( I tried everything.

MrFaciio
Автор

3:11 "I am not very good at english..."

Proceeds to Code in english 😅

dertobbe
Автор

Idk it doesnt work for me. Idk what i did wrong... Like my Ui its not shown on my game screen

darredYouTube
Автор

so underrated video. Thank you very much!

frantisek
Автор

Nice tutorial, what a pity that it is only for orthographic cameras

optus
Автор

Great Video, thank you! Question: can this script be used on a Canvas object and still work??

billbuckman
Автор

i had to remove the multiplication by 100 otherwise it was becoming 1000 on scale. When i was trying to scale it on a landscape mode the width wasnt properly adjusted only the height was. but i found a solution, I hope it works anyone who had the same problem as me.

using UnityEngine;

public class Test : MonoBehaviour
{
[SerializeField]private Camera mainCam;

private void Start()
{
transform.position = new Vector3(mainCam.transform.position.x, mainCam.transform.position.y, 0);
Vector3 bottomLeft =
Vector3 topRight = Vector3(mainCam.rect.width, mainCam.rect.height));
Vector3 screenSize = topRight - bottomLeft;

if(transform.localScale.x < screenSize.x || transform.localScale.x> screenSize.x)
{
transform.localScale = new Vector3(screenSize.x, screenSize.y, 1f);
}
}
}

alice
Автор

Hey, great solution!
I'm having a problem where i place a canvas inside of it and the elements dissapear, do you know whats going on?

soyrandom
Автор

Its not working for me, plz help
the problem is that I create a game object with this script but no gray bg appears on which I could put my child objects

ghauswood
Автор

dude microphone volume is ultra low please high your volume of mic beacuse i heard very queit what is you said

abnormalaestheticsstudio
Автор

Im making my first game, and it doesnt really work for me, maybe im dumb lolz ill save the video, it might be that my game is just scuffed xD

swepo
Автор

Vector3 bottomLeft = * 100;
Vector3 topRight = Vector3(maingcamera.rect.width, maingcamera.rect.height)) * 100;

I had to multiply it by 1 instead of 100 for it to work properly, but if I multiply it by 100, the object becomes larger than the camera.

sakaring
Автор

That does not work with canvases, does you have any other way to deal with that?

somerndguy
Автор

היי עידו הסתבכתי קצת יש מצב אתה עוזר לי?

Blessed
Автор

mate you need to improve your voice, the sound is soo low,

TechWrathTV