Sharp Coder is reader-supported, meaning when you buy through links on our site, we may earn an affiliate commission.
Script for Creating a Light Switch in Unity
2D Coin Collecting in Unity
How to Use Xbox Controller in Unity
Raycast and Projectile-based Gun Shooting Script for Unity
How to Set Up Joystick Controller for Movement in Unity
2D Melee Attack Tutorial for Unity
Top Unity Assets From the Asset Store

Unity FPS Counter

In video games, frames-per-second (or fps for short) is a value that represents the number of frames that the computer renders in one second.

Frames-per-second is a great indicator of performance and can be used during the optimization process, or simply to get feedback on how fast/smooth the game runs.

In this tutorial, I will be showing how to add a simple fps counter to your game in Unity.


To show fps in the game, we will need to create a script that will count frames and show them on the screen.

  • Create a new script, call it "SC_FPSCounter" and paste the code below inside it:


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

public class SC_FPSCounter : MonoBehaviour
    /* Assign this script to any object in the Scene to display frames per second */

    public float updateInterval = 0.5f; //How often should the number update

    float accum = 0.0f;
    int frames = 0;
    float timeleft;
    float fps;

    GUIStyle textStyle = new GUIStyle();

    // Use this for initialization
    void Start()
        timeleft = updateInterval;

        textStyle.fontStyle = FontStyle.Bold;
        textStyle.normal.textColor = Color.white;

    // Update is called once per frame
    void Update()
        timeleft -= Time.deltaTime;
        accum += Time.timeScale / Time.deltaTime;

        // Interval ended - update GUI text and start new interval
        if (timeleft <= 0.0)
            // display two fractional digits (f2 format)
            fps = (accum / frames);
            timeleft = updateInterval;
            accum = 0.0f;
            frames = 0;

    void OnGUI()
        //Display the fps and round to 2 decimals
        GUI.Label(new Rect(5, 5, 100, 25), fps.ToString("F2") + "FPS", textStyle);
  • Attach the SC_FPSCounter script to any object in the Scene and press Play:


Fps should now be displayed in the top-left corner.

You Do Not Have To Do Everything Yourself
Search from thousands of ready-to-use Unity assets.
Visit Asset Store