Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. 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,947
    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