Search Unity

Text somtimes flickering during update.

Discussion in 'UGUI & TextMesh Pro' started by Klik303, Nov 8, 2017.

  1. Klik303

    Klik303

    Joined:
    Dec 10, 2016
    Posts:
    19
    Hi.
    Is anyone can tell me why my time text is flickering sometimes during update?

    Code:
    Code (CSharp):
    1. public class Timer : MonoBehaviour {
    2.      
    3.     private float time = 0;
    4.     private Text textDisplay;
    5.  
    6.     void Start()
    7.     {
    8.         textDisplay = gameObject.GetComponent<Text>();
    9.     }
    10.     void Update()
    11.     {
    12.         time += Time.deltaTime;      
    13.         var minutes = time / 60;
    14.         var seconds = time % 60;
    15.         var milliseconds = (time * 100) % 100;
    16.        
    17.         textDisplay.text = string.Format("{0:00} : {1:00} : {2:00}", minutes, seconds, milliseconds);
    18.     }
    19.    
    20. }
    Thank you.
     
  2. hamberge

    hamberge

    Joined:
    Aug 30, 2015
    Posts:
    36
    What do you mean by flickering?
     
  3. Klik303

    Klik303

    Joined:
    Dec 10, 2016
    Posts:
    19
    I mean, in some frames instead of proper time something else is display there. It is quite difficult to say what is there when it takes only short time. It looks like sometimes displaying time has different string format then I set in code.
     
  4. hamberge

    hamberge

    Joined:
    Aug 30, 2015
    Posts:
    36
    Any chance you have another component setting the text as well?
     
  5. Klik303

    Klik303

    Joined:
    Dec 10, 2016
    Posts:
    19
    OK. I recorded my screen as video and I cached that moments.
    This is correct:
    good.jpg
    And correction:
    bad.jpg

    So now we know where is a problem. But question is why sometimes there is 3 digits if in code I restricted to 2 digits?
    And how to fix it?

    Thank you.