무료 가로 세로 비율로 최신 유니티 버전의 간단한 2D 게임을 만들었지 만, 화면을 세로 또는 가로로 변경하면 엉망입니다. 지금은 튜토리얼을 따라 하루 종일 보냈고 사용 가능한 모든 자습서 나 답변을 살펴 보았지만 이상하게도 코드 중 하나도 도움이되지 않았습니다. 여기 내 화면이 코드유니티 안드로이드 화면 해상도
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Screeratio : MonoBehaviour {
// Use this for initialization
void Start() {
// set the desired aspect ratio (the values in this example are
// hard-coded for 16:9, but you could make them into public
// variables instead so you can set them at design time)
float targetaspect = 16.0f/9.0f;
// determine the game window's current aspect ratio
float windowaspect = (float)Screen.width/(float)Screen.height;
// current viewport height should be scaled by this amount
float scaleheight = windowaspect/targetaspect;
// obtain camera component so we can modify its viewport
Camera camera = GetComponent<Camera>();
// if scaled height is less than current height, add letterbox
if (scaleheight < 1.0f)
{
Rect rect = camera.rect;
rect.width = 1.0f;
rect.height = scaleheight;
rect.x = 0;
rect.y = (1.0f - scaleheight)/2.0f;
camera.rect = rect;
}
else // add pillarbox
{
float scalewidth = 1.0f/scaleheight;
Rect rect = camera.rect;
rect.width = scalewidth;
rect.height = 1.0f;
rect.x = (1.0f - scalewidth)/2.0f;
rect.y = 0;
camera.rect = rect;
}
}
// Update is called once per frame
void Update() {
}
}
를 사용하고 있는데이 아무튼 지금은 서로 다른 해상도
을 모습입니다 '잘 작동하는 것 같아. 게임이 모든 화면 크기에서 원활하게 실행되도록하려면 어떻게해야합니까?
UGUI인가요? 어쩌면 게임에서 인물과 풍경 모두를 원한다면 각각을 위해 디자인하는 것이 좋습니다. UGUI를 사용하는 경우 앵커를 사용하고 컨트롤을 위해 부모를 설정할 수 있습니다. – ATHellboy
@ATHellboy 아래에서 내 코멘트를 확인하십시오 – melissa