Here is little script where you can show the current, the average, the minimum and maximum FPS of your game.

Attach the followed script on a canvas where you have created 4 input text, one for each status :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class FPSAverage : MonoBehaviour {
    // Display UI
    [SerializeField]
    Text currentFPS;
    [SerializeField]
    Text averageFPS;
    [SerializeField]
    Text maxFPS;
    [SerializeField]
    Text minFPS;

    int framesPassed = 0;
    float fpsTotal = 0f;
    float minFPSValue = Mathf.Infinity;
    float maxFPSValue = 0f;

    // Start is called before the first frame update
    void Start () {
        Application.targetFrameRate = 60;
    }

    // Update is called once per frame
    void Update () {
        // Current FPS value
        float fps = 1 / Time.unscaledDeltaTime;
        currentFPS.text = "Cur. FPS: " + (int) fps;

        // Calculate average
        fpsTotal += fps;
        framesPassed++;
        averageFPS.text = "Ave. FPS: " + (int) (fpsTotal / framesPassed);

        // Max FPS
        if (fps > maxFPSValue && framesPassed > 10) {
            maxFPSValue = fps;
            maxFPS.text = "Max FPS: " + (int) maxFPSValue;
        }

        // Min FPS
        if (fps < minFPSValue && framesPassed > 10) {
            minFPSValue = fps;
            minFPS.text = "Min. FPS: " + (int) minFPSValue;
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *