Search Unity

  1. We want you to join us at GDC this year! Take a peek at all of the events we will be hosting during the week of GDC.
    Dismiss Notice
  2. Tell us about your experience here and you’ll get early access to the 2018 Game Studios report + more goodies.
    Dismiss Notice
  3. Unity 2017.3 has arrived! Read about it here.
    Dismiss Notice
  4. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  5. We've closed the job boards. If you're looking for work, or looking to hire check out Unity Connect. You can see more information here.
    Dismiss Notice

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:
    38
    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

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