Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

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

Discussion in 'Physics' started by Danka7z, Jun 13, 2015.

  1. Danka7z

    Danka7z

    Joined:
    Jun 13, 2015
    Posts:
    2
    Hi Guys! 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.

    //---------------------------------------------
    // 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. SeriousBusinessFace

    SeriousBusinessFace

    Joined:
    May 10, 2014
    Posts:
    127
    I don't know why your FPS is doing that. I do have a different suggestion; there's no need to re-create the GUIStyle each OnGUI call; you can just create it once in Start() and store it in a variable.
     
  3. Danka7z

    Danka7z

    Joined:
    Jun 13, 2015
    Posts:
    2
    You're right, but it doesn't solve a problem. The mobile requires touching screen constantly to provide optimal number of FPS. How can I do this ?