WaitForSeconds is Not Working

Hi,
I want to create a digital clock affect using coroutines but it does’nt work
code:

public class Clock : MonoBehaviour {

[SerializeField]Text clockText;
DateTime currentTime = DateTime.Now;

// Use this for initialization
void Update () {
StartCoroutine (EnableText ());
StartCoroutine (DisableText ());
}

private IEnumerator EnableText(){
clockText.text = currentTime.Hour.ToString () + " " + currentTime.Minute.ToString ();
yield return new WaitForSeconds(1.5f);
}

private IEnumerator DisableText(){
clockText.text = currentTime.Hour.ToString () + “:” + currentTime.Minute.ToString ();
yield return new WaitForSeconds(1.5f);

}
}

What am i missing?

Please use code tags.

You also need to tell us what’s happening, as “not working” isn’t much to go on. You also need to tell us what you’re trying to do, which isn’t clear from your post.

I can see that you’re starting coroutines in Update, which is probably wrong, as you’re getting two new coroutines every frame. The coroutines are also doing a WaitForSeconds at their end, which doesn’t do anything, so it seems like you believe that thing work very differently from how they do, EnableText and DisableText is also the exact same code, which is strange.

If you want the code to be delayed, you need to place it after the waitforseconds and not before it.

Thanks!

Right code for making a digital clock with blinking colon:

using UnityEngine;
using System;
using UnityEngine.UI;
using System.Collections;

public class Clock : MonoBehaviour {

    [SerializeField]Text clockText;
  
    void Start () {
        StartCoroutine (EnableText ());
    }

    private IEnumerator EnableText(){
        yield return new WaitForSeconds(1f);
        clockText.text = DateTime.Now.Hour.ToString () + " " + DateTime.Now.Minute.ToString ();
        OneDigitCheck (false);
        StartCoroutine (DisableText ());
    }

    private IEnumerator DisableText(){
        yield return new WaitForSeconds(1f);
        clockText.text = DateTime.Now.Hour.ToString () + ":" + DateTime.Now.Minute.ToString ();
        OneDigitCheck (true);
        StartCoroutine (EnableText ());

    }

    void OneDigitCheck(bool colonEnabled)
    {
        if (DateTime.Now.Minute < 10) {
            if(colonEnabled)
            {
                clockText.text = DateTime.Now.Hour.ToString () + ":0" + DateTime.Now.Minute.ToString ();
            }
            else{
                clockText.text = DateTime.Now.Hour.ToString () + " 0" + DateTime.Now.Minute.ToString ();
            }
        }
    }
}