動作確認
Unity 5.1.2-f1 on MacOS X 10.8.5
androidにアプリを転送してみたが、UI>Buttonなどがすごく小さく表示されてしまった。
try01
とりあえず、以下のようにしてButtonなどの表示を大きくできる。
void Start () {
float screenRate = 4.0f;
int width = (int)(Screen.width / screenRate);
int height = (int)(Screen.height / screenRate);
Screen.SetResolution (width, height, false);
}
参考
http://tamilabo.blog.fc2.com/blog-entry-14.html
try02
どうもtry01のコードで実装すると Application.LoadLevel()で別シーンから再度戻ってきた時にも再度解像度を変更してしまう。
以下のようにmyButtonの幅がスクリーンの50%になるようにすると、シーン間の遷移による問題は避けることができる。
MainCameraControl.cs
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class MainCameraControl : MonoBehaviour {
public Text msgText; // set Text to show message
public Button myButton; // set UI>Button whose width is used as standard
void Start () {
float aspect = (float)Screen.height / (float)Screen.width;
float buttonRatio = 0.5f; // 50%
int buttonWidth = (int)myButton.GetComponent<RectTransform> ().rect.width;
float newWidth, newHeight;
newWidth = buttonWidth / buttonRatio;
newHeight = newWidth * aspect;
Screen.SetResolution ((int)newWidth, (int)newHeight, false);
msgText.text = newWidth.ToString () + "x" + newHeight.ToString ();
}
}