2017-11-11 23 views
0

まあ、私のUI要素が、それは私がカメラユニティのUI doesntの規模を適切

public class CameraResolutionFix : MonoBehaviour { 
public float orthographicSize = 5; 
public float aspect = 1.33333f; 
void Start() 
{ 
    Camera.main.projectionMatrix = Matrix4x4.Ortho(
     -orthographicSize * aspect, orthographicSize * aspect, 
     -orthographicSize, orthographicSize, 
     GetComponent<Camera>().nearClipPlane, GetComponent<Camera>().farClipPlane); 
} 
に添付のスクリプトとは何かを持っているかなり確信して異なる画面解像度とIMの私の2Dアンドロイドのゲームでスケーリングアレントをスケーリングアレントあなたは CanvasScalerを使用したいと思うかもしれない

}

答えて

0

、以下のコードは私のために正常に動作します:

enter image description here

using System.Collections; 
using System.Collections.Generic; 
using UnityEngine; 
using UnityEngine.UI; 

/// <summary> 
/// Attach this script to objects that has a CanvasScaler component. 
/// 
/// This makes sure the UI enlarges/shrinks when the device resolution changes. 
/// 
/// scaleFactor = 1.333f * Screen.height/640; 
/// Galuxy Notes 4: 2560X1440, iphone 5s: (1136X640) 
///   |       | 
///   v       v 
/// scaleFactor = 3     scaleFactor = 1   
/// </summary> 
public class DynamicCanvasScaler : MonoBehaviour { 


    void Start() { 
     AdjustDynamicCanvasScalar(); 

    } 
    /// <summary> 
    /// Canvas Scalar determins how large the UI elements are. On high resolution 
    /// deveices, this value should be larger, to make sure it is clearly visible 
    /// and on low resolution devices, this should be kept smaller so that the UI 
    /// menus are not so big. 
    /// </summary> 
    private void AdjustDynamicCanvasScalar() 
    { 
     var cs = gameObject.GetComponent<CanvasScaler>(); 
     if (cs == null) 
      Debug.LogError("Cannot find the canvas scalar"); 
     else 
     { //Galuxy Notes 4: 2560X1440, iphone 5s: (1136X640) 
      cs.scaleFactor = 1.333f * Screen.height/640; 
      Debug.Log("----------" + "Canvas Scalar = " + cs.scaleFactor + " ----------"); 
     } 
    } 
} 
関連する問題