(UNITY3d android game) When i don't touch the screen, my fps are lower than when i touch

617 views Asked by At

I've had a problem for a long time with smooth camera on mobile phone (platformer game), but I reported that my game works well when my fps don't drop below 60. I notice that my fps are fine when i touch a screen, but when i don't do it, fps drop to approximately 58, 59 and after that my camera don't follow my player smoothly. For testing i create new scene with only FPSCounter script and the effects are the same. Could someone help me with it? I think that it is engine settings reasons, but i can't handle with it.emphasized text

//---------------------------------------------
// 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;
}

2

There are 2 answers

0
Little-God On

Have you tried using the new UI system introduced in Unity 4.6? Maybe that fixes your issues. https://www.youtube.com/watch?v=EOX6itCuKOc

0
Joekomino On

As previously mentioned, you should really switch to the new UI system as the old GUI system was always a nightmare.

However, if you aren't wanting to switch, try setting more of your variables outside of OnGUI.

OnGUI is called multiple times per frame and it is expensive to set up a GUI style etc. so frequently - especially on an already poorly performing behaviour.