Jump to content
Unity Insider Forum
Thariel

FPS Anzeige

Recommended Posts

Hier mein Script zur Anzeige der FPS.

Einfach der Szene hinzufügen (vorzugsweise auf ein Text Ui) und eine Referenz eines beliebigen Text Ui hinzufügen.

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

/// <summary>
/// This script calculate the current fps and show it to a text ui.
/// </summary>
public class UiDisplayFps : MonoBehaviour
{
    public string formatedString = "{value} FPS";
    public Text txtFps;

    public float updateRateSeconds = 4.0F;

    int frameCount = 0;
    float dt = 0.0F;
    float fps = 0.0F;

    void Update()
    {
        frameCount++;
        dt += Time.unscaledDeltaTime;
        if (dt > 1.0 / updateRateSeconds)
        {
            fps = frameCount / dt;
            frameCount = 0;
            dt -= 1.0F / updateRateSeconds;
        }
        txtFps.text = formatedString.Replace("{value}", System.Math.Round(fps, 1).ToString("0.0"));
    }
}

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×