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

Adding FPSCounter.cs to game screen

Discussion in 'Scripting' started by karimcambridge, Nov 13, 2015.

  1. karimcambridge

    karimcambridge

    Joined:
    May 3, 2014
    Posts:
    4
    Hello, I attached the FPSCounter.cs script to the third person controller. Any idea why it isn't working?

    Unity 5.2.2.

    There is also the default Text script attached to the third person controller. When I change that text nothing comes up on the scene.

    Code (CSharp):
    1. using System;
    2. using UnityEngine;
    3. using UnityEngine.UI;
    4.  
    5. namespace UnityStandardAssets.Utility
    6. {
    7.     [RequireComponent(typeof (Text))]
    8.     public class FPSCounter : MonoBehaviour
    9.     {
    10.         const float fpsMeasurePeriod = 0.5f;
    11.         private int m_FpsAccumulator = 0;
    12.         private float m_FpsNextPeriod = 0;
    13.         private int m_CurrentFps;
    14.         const string display = "{0} FPS";
    15.         private Text m_Text;
    16.      
    17.         private void Start()
    18.         {
    19.             m_FpsNextPeriod = Time.realtimeSinceStartup + fpsMeasurePeriod;
    20.             m_Text = GetComponent<Text>();
    21.         }
    22.      
    23.         private void Update()
    24.         {
    25.             // measure average frames per second
    26.             m_FpsAccumulator++;
    27.             if (Time.realtimeSinceStartup > m_FpsNextPeriod)
    28.             {
    29.                 m_CurrentFps = (int) (m_FpsAccumulator/fpsMeasurePeriod);
    30.                 m_FpsAccumulator = 0;
    31.                 m_FpsNextPeriod += fpsMeasurePeriod;
    32.                 m_Text.text = string.Format(display, m_CurrentFps);
    33.             }
    34.         }
    35.     }
    36. }
    37.  
     
    Last edited: Nov 13, 2015
  2. Captain-Awesome

    Captain-Awesome

    Joined:
    Jul 29, 2014
    Posts:
    28
    I don't know, my FPS counter just broke one day after an update.
     
  3. overfile

    overfile

    Joined:
    Oct 21, 2013
    Posts:
    27
    Text is an UI element. If text doesn't attach with Canvas... You don't controll where showing.