반응형
- 코드 작성
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraResolution : MonoBehaviour
{
private void Start()
{
SetResolution();
}
public void SetResolution()
{
int setWidth = 1080;
int setHeight = 1920;
int deviceWidth = Screen.width;
int deviceHeight = Screen.height;
Screen.SetResolution(setWidth, (int)(((float)deviceHeight / deviceWidth) * setWidth), true);
if ((float)setWidth / setHeight < (float)deviceWidth / deviceHeight)
{
float newWidth = ((float)setWidth / setHeight) / ((float)deviceWidth / deviceHeight);
Camera.main.rect = new Rect((1f - newWidth) / 2f, 0f, newWidth, 1f);
}
else
{
float newHeight = ((float)deviceWidth / deviceHeight) / ((float)setWidth / setHeight);
Camera.main.rect = new Rect(0f, (1f - newHeight) / 2f, 1f, newHeight);
}
}
}
참고할만한 글
반응형