Instantiate Particles, WaitForSeconds and continue


I have been working with trying to achieve the following:

1) Player Steps onto a trigger

  1. Player Presses a key while on trigger to Instantiate particles

  2. Particles instantiate

  3. Start to WaitForSeconds(3.5f)

  4. End of 3.5 seconds->Fade Particles out by code (ParticleAnimator)

  5. WaitForSeconds(3.5f)

  6. End of 3.5 seconds->Reinstantiate Particles (may be unecessary)

Steps 4 - 7 should continue doing so until the Player moves i.e. (Mathf.Abs(PlayerMoveScript.MoveForward) > 0)) even if Player remains on trigger.

I can start by showing the code for when the player presses a key to instantiate particles (assuming everything is declared):

OnTriggerStay(Collider other)
    void InstantiateParticles()
        if (Input.GetKeyDown("space") && PlayerMoveScript.MoveForward == 0)
            if (RedParticles != null && theRedParticles == null)
                Debug.Log("Preparing to instantiate");
                theRedParticles = (GameObject) Instantiate(RedParticles, transform.position, Quaternion.identity);
                newRedParticles = (GameObject) RedParticles;

private IEnumerator FadeParticles()
        yield return StartCoroutine(Wait())

            if (theRedParticles != null)

                holder = new Color[5];
                holder = theRedParticles.GetComponent<ParticleAnimator>( ).colorAnimation;

                for (int x=0; x<5; x++) 
                    holder[x].a -= 0.02f;

                theRedParticles.GetComponent<ParticleAnimator>( ).colorAnimation = holder;

                yield return StartCoroutine(Wait());
                Debug.Log("Done Waiting Again..");
                // try to use another prefab with the same qualities.
                theRedParticles = newRedParticles;

        yield return 0;

private IEnumerator Wait()
    yield return new WaitForSeconds(3.5f);

Revised code Result: The code does not wait for 3.5 seconds, for some reason.

Just quickly looking at your code I noticed one issue. You have a static IEnumerator method and that doesn't work. Methods with yield commands can not be static.