반응형
- 코드 작성
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);
}
}
}
참고할만한 글
반응형
'개발 > C#' 카테고리의 다른 글
유니티 C# String Enum 타입 간단 변환 (0) | 2022.10.24 |
---|---|
유니티 C# Enum Count 길이 간단 구하기 (0) | 2022.09.20 |
유니티 C# 마우스 좌표 Mouse Position 간단 구하기 (0) | 2022.09.20 |
유니티 C# NGUI 가변 해상도 대응 IOS 간단 사용법 (0) | 2022.08.28 |
유니티 C# 베터리 잔량 가져오기 Battery 간단 사용법 (0) | 2022.08.25 |
유니티 C# 로컬 푸시 알림 Local Push Notification 간단 구현 (0) | 2022.08.17 |
유니티 C# 부모 자식 오브젝트 가져오기 GetChild 간단 사용법 (0) | 2022.08.17 |
유니티 C# 리소스 로드 Resource.Load 함수 간단 사용법 (0) | 2022.08.17 |
댓글