using UnityEngine;
using System.Collections;
public class GUIScreenFit : MonoBehaviour {
void OnGUI(){
///下面代码问题:使用不同分辨率,位置和大小会发生变化
//if (GUI.Button (new Rect (Screen.width - 200, Screen.height - 100, 64, 64), "Start")) {
//}
///解决方案:按比例去移动和缩放UI
if (GUI.Button (new Rect (Screen.width - 200 * m_fScaleWidth, Screen.height - 100 * m_fScaleHeight, 64 * m_fScaleWidth, 64 * m_fScaleHeight), "Start")) {
}
}
///定义基准屏幕大小
float m_fScreenWidth = 480;
float m_fScreenHeight = 854;
///分别记录当前屏幕长宽与基准屏幕长宽之比
float m_fScaleWidth;
float m_fScaleHeight;
void Awake(){
m_fScaleWidth = (float)Screen.width / m_fScreenWidth;
m_fScaleHeight = (float)Screen.height / m_fScreenHeight;
}
}