Search Unity

Entire canvas is yellow after running an FPS script.

Discussion in 'Scripting' started by pilchardDev, Sep 13, 2017.

  1. pilchardDev

    pilchardDev

    Joined:
    Aug 20, 2016
    Posts:
    40
    Hello, I've pulled an FPS counter script from ' http://wiki.unity3d.com/index.php?title=FramesPerSecond ' (I've slightly modified it for my use.)

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.UI;
    4. public class HUDFPS : MonoBehaviour
    5. {
    6. public  float updateInterval = 0.5F;
    7. private float accum   = 0;
    8. private int   frames  = 0;
    9. private float timeleft;
    10.  
    11. public Text guiText;
    12. void Start()
    13. {
    14.     guiText = this.GetComponent<Text>();
    15.     timeleft = updateInterval;
    16. }
    17. void Update()
    18. {
    19.     timeleft -= Time.deltaTime;
    20.     accum += Time.timeScale/Time.deltaTime;
    21.     ++frames;
    22.     if( timeleft <= 0.0 )
    23.     {
    24.     float fps = accum/frames;
    25.     string format = System.String.Format("{0:F2} FPS",fps);
    26.     guiText.text = format;
    27.     if(fps < 30)
    28.         guiText.material.color = Color.yellow;
    29.     else
    30.         if(fps < 10)
    31.             guiText.material.color = Color.red;
    32.         else
    33.             guiText.material.color = Color.green;
    34.         timeleft = updateInterval;
    35.         accum = 0.0F;
    36.         frames = 0;
    37.     }
    38. }
    39. }
    Ever since I ran this script, everything on my canvas has a yellow tint. Anyone able to explain this, and give me a lead on out to fix it? Thankyou :)

    Kind Regards, Lachlan
     
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,620
    Use guiText.color = Color.yellow rather than setting it in the material?
     
    karl_jones likes this.