2017-09-18 10 views
0

무료 가로 세로 비율로 최신 유니티 버전의 간단한 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() { 

     } 
    } 

를 사용하고 있는데이 아무튼 지금은 서로 다른 해상도

무료 화면 enter image description here 초상화 enter image description here 풍경

enter image description here

을 모습입니다 '잘 작동하는 것 같아. 게임이 모든 화면 크기에서 원활하게 실행되도록하려면 어떻게해야합니까?

+0

UGUI인가요? 어쩌면 게임에서 인물과 풍경 모두를 원한다면 각각을 위해 디자인하는 것이 좋습니다. UGUI를 사용하는 경우 앵커를 사용하고 컨트롤을 위해 부모를 설정할 수 있습니다. – ATHellboy

+0

@ATHellboy 아래에서 내 코멘트를 확인하십시오 – melissa

답변

1

캔버스를 사용하십니까? 앵커의 배치에주의를 기울여야합니까?
지금 사용하는 방법을 모르면 this video을 예로들 수 있습니다.

게임은 가로 모드 또는 다른 방향으로 만 플레이 할 수 있습니까?
편집> 플레이어> 해상도 및 프리젠 테이션 탭에서보기를 세로 또는 가로로 수정할 수 있습니다.

+0

세로보기가 내 게임에서 벗어나기 위해 가로 방향을 변경했습니다. 제가 사용하고있는 유일한 UI 요소는 텍스트입니다 (캔버스가 붙어있는 상태에서도 잘 작동하지 않습니다. 화면 크기의 눈금이있는 경우), 나머지는 모두 이미지이므로 캔버스 안쪽에 넣어야할지 안할지 확신하지 못합니다. 캔버스에 넣지 않으면 배경이 다른 장치에서 잘 작동하는지 어떻게 확인할 수 있습니까? – melissa

+0

모두 캔버스에 넣어야합니다. 배경 이미지 및 버튼의 텍스트는 버튼 객체의 자식이어야합니다. 캔버스 도구를 처음 사용하는 경우 [캔버스 공식 유니트 투트] (https://unity3d.com/fr/learn/tutorials/topics/user-interface-ui/ui-canvas)를 확인하십시오. – DavEat