Global variable not recognized in For loop : <p>I have the following C# script for managing some particle system physics in Unity:</p>

<pre><code>//PS Variables
ParticleSystem myPS;
public List&lt;ParticleCollisionEvent&gt; collisisonEvents;

//Physics variables
public float effect;    


// Use this for initialization
void Start () {
    myPS = GetComponent&lt;ParticleSystem&gt;();
    collisisonEvents = new List&lt;ParticleCollisionEvent&gt;();
}


void OnParticleCollision (GameObject other)
{
    //Checking if the hit object is indeed the ball
    bool isBall = other.tag.Equals("Player");
    if (isBall)
    {
        Rigidbody2D hitObject = other.GetComponent&lt;Rigidbody2D&gt;();

        //Getting the number of collisions that have occured this frame
        int numOfCollisions = myPS.GetCollisionEvents(other, collisisonEvents);
        Vector3 particleDirection = new Vector2(0,0);

        //Iterating through all the events
        for (int i = 0; i &lt; numOfCollisions; i++)
        {
            //Calculating a resultant direction
            particleDirection += collisionEvents[i].velocity;
        }

        //Applying the resultant force
        hitObject.AddForce(particleDirection.normalized * effect * numOfCollisions);
    }
}
</code></pre>

<p>There seems to be a problem with the scope of the <strong>collisionsEvents</strong> list though, as I cannot use it in the for loop in the OnParticleCollision co-routine. I keep on getting the error that "collisionsEvents does not exist in this current context." The variable myPS doesn't have this problem though, and it was declared in the same place as collisionsEvents.</p>

<p>Could anyone please help me here?</p>
