foreach GameObject condition error

Hi,

When the player instantiates a particlePrefab, particles emit at the players position. What I need to do is for when the player moves, I need the particles to move with the player, in the direction the player is going, and also to gradually destroy several of the particles (not all of them at once).

Essentially, the player runs up to a trigger, player instantiates particles, player moves, and the particles destroy immediately (not what I want). I need to gradually destroy particles in the direction the player moves in...for now, I am working on gradually destroy particles (fading them out) while holder[4].a is > 0.

`//In seperate script file
public static GameObject instantiated
;

instantiated = (GameObject) Instantiate(particlePrefab, transform.position, Quaternion.identity);
//End seperate script file
//Call our coroutine to gradually destroy particles

public static IEnumerator ResetParticles()
{

resetting = true;
holder = new Color[5];
holder[4].a = 1;

while (holder[4].a > 0) 
{
    foreach (ParticleAnimator m_emitter in emitters) 
    {
        if (m_emitter) 
        {                   
            holder = m_emitter.colorAnimation;
            holder[4].a -= .005f;
            m_emitter.colorAnimation = holder;
        }
    }
}
foreach (ParticleAnimator m_emitter in emitters) 
{
    if (m_emitter) 
    {
        m_emitter.particleEmitter.emit = false;
        m_emitter.particleEmitter.ClearParticles();
    }
}
    resetting = false;
    sent = false;

yield return 0;

}
`

What the above does, without a PreFab instantiation is destroy's particles gradually. I need to be able to use my instantiated GameObject varaible because it has the instantiated particle prefab.

Note: This answer was posted before the asker decided to completely rewrite their question, adding more details. This answer may no longer apply.

What are you trying to accomplish here? Perhaps if you actually explained your goal, we may be able to help better (instead of just posting code and saying "this doesn't work, help me").

Regardless, the problem is that you're trying to iterate through a variable that isn't a collection. A GameObject isn't an array or a collection, there isn't "more than one of them", so you can't use a foreach on it. I think you just want to do this:

PlayerDidStuff.instantiated.particleEmitter.emit = true;