Yield return new waitforseconds(5) does not work?

using UnityEngine;
using System.Collections;

public class Logofadein : MonoBehaviour
{

    public float fadeSpeed = 1f;
    float Fade = 0;
    public bool fadeIn = true;
    public SpriteRenderer text;
    IEnumerator musicdelay()
    {
        yield return new WaitForSeconds(5);
    }

    // Use this for initialization

    // Invisible on Awake
    void Awake()
    {
        text.color = new Color(1f, 1f, 1f, 0f);
        StartCoroutine(musicdelay());
    }


    // Update is called once per frame
    void Update()
    {
        if (fadeIn)
        {
            text.color = new Color(1f, 1f, 1f, Fade += .001f);
        }
    }
}

The code works, but it doesn’t wait 5 seconds before executing. It just goes straight into it. What is the problem…?

Hi,

I come from the c# world so I might be wrong.
I think your problem is that your coroutine contains only a wait.
It starts, does nothing for 5 seconds then it’s over. You need to place whatever you want the delay on after the yield.

LuckierBread is correct. You have have the system waiting for 5 seconds (5f) but there are no commands after the timer is over. You need to have the music play after that code. I also don’t see a
public AudioClip music = null; reference to any audio clip you are attempting to play after the Coroutine. Try This…

using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;

[RequireComponent(typeof(AudioSource))]

public AudioClip music = null;

IEnumerator musicdelay()
     {
         yield return new WaitForSeconds(5f);
        GetComponent<AudioSource>().PlayOneShot(music, 1f);

        yield return new WaitForSeconds(5f);
        SceneManager.LoadScene("titleScreen"); // Whatever level your loading after.
     }