我在手機(遊戲平臺遊戲)上遇到了一個很長時間的問題,但我報告說當我的fps不低於60時,我的遊戲運行良好。我注意到,當我觸摸屏幕時,我的fps很好,但是當我不這樣做時,fps下降到大約58,59,之後,順利地跟隨我的球員。對於測試,我只用FPSCounter腳本創建新場景,效果是一樣的。有人可以幫我嗎?我認爲這是引擎設置的原因,但我無法處理它。 強調文本 (UNITY3D安卓遊戲)當我不觸摸屏幕時,我的fps比我觸摸的時候更低
//---------------------------------------------
// VARIABLES
//---------------------------------------------
private float deltaTime = 0.0f;
//---------------------------------------------
// METHODS FROM SUPERCLASS
//---------------------------------------------
void Update()
{
deltaTime += (Time.deltaTime - deltaTime) * 0.1f;
}
void OnGUI()
{
GUIStyle style = new GUIStyle();
float x = Screen.width - 110;
float fps = 1.0f/deltaTime;
Rect rect = new Rect(x, 90, 100, 50);
style.fontSize = 18;
style.normal.textColor = getColor(fps);
string text = string.Format("{0:0,0.0000 FPS}",fps);
GUI.Label(rect, text, style);
}
//---------------------------------------------
// CLASS LOGIC
//---------------------------------------------
private Color getColor(float fps)
{
if (fps >= 60)
{
return Color.yellow;
}
return Color.red;
}