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. Dismiss Notice

Question How to round fps variable.

Discussion in 'Scripting' started by PanPrezess, Aug 19, 2020.

  1. PanPrezess

    PanPrezess

    Joined:
    Aug 17, 2020
    Posts:
    8
    How to round fps amount correct?

    I think i should add f somewhere in Mathf.Round(fps);
    But i don't know where.

    Code:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using TMPro;
    6.  
    7. public class fpsCounter : MonoBehaviour
    8. {
    9.  
    10.     public TMP_Text fpsCounter_txt;
    11.  
    12.     void Update(){
    13.         float fps = 1 / Time.unscaledDeltaTime;
    14.         Mathf.Round(fps);
    15.         fpsCounter_txt.text = "fps: " + fps;
    16.     }
    17. }
    Thanks in advance.
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,722
    You need to capture the result of the Round operation somewhere! Also you'll want it as an int, so use RoundToInt:
    Code (CSharp):
    1.     void Update(){
    2.         float fps = 1 / Time.unscaledDeltaTime;
    3.         int roundedFps = Mathf.RoundToInt(fps);
    4.         fpsCounter_txt.text = "fps: " + roundedFps;
    5.     }
     
    PanPrezess likes this.
  3. PanPrezess

    PanPrezess

    Joined:
    Aug 17, 2020
    Posts:
    8