I'm trying to learn how to access and assign code to individual particles in an array. Say I started with something like the script reference...
function LateUpdate () {
// extract the particles
var particles = particleEmitter.particles;
for (var i = 0; i < particles.Length; i++) {
// Move the particles up and down on a sinus curve
var yPosition = Mathf.Sin (Time.time) * Time.deltaTime;
particles*.position += Vector3 (0, yPosition, 0);*
*// make the particles red*
_particles*.color = Color.red;*_
_*// modify the size on a sinus curve*_
<em><em>particles_.size = Mathf.Sin (Time.time) * 0.2;_</em></em>
<em>_*}*_</em>
<em>_*// copy them back to the particle system*_</em>
<em>_*particleEmitter.particles = particles;*_</em>
<em>_*}*_</em>
<em>_*```*_</em>
<em><em><em><p>This modifies the entire array. What if I want to do something like randomize the x value for each separate particle? I know how to randomize but what I'm struggling with is getting this to be applied to each "array member" individually. I tried taking the "particleEmitter.particles = particles;" line and putting it back into the for loop along with adding <em>to both - (particleEmitter.particles _= particles*;), and it seems to do null out the code in the for loop.</p>*_</em></em></em></em>
You only want to extract the particles into the array, and put the array back into the particle system, one time.
Once you have the array, you can do whatever you want to each element. That's what the loop is doing. It's walking each element of the array and modifying it. You could make that loop skip every other particle, or remove the loop and only change the first particle in the array. It's up to you.
So hopefully you now see that the lines you want to change are entirely inside the loop. Specifically, change these:
// Move the particles up and down on a sinus curve
var yPosition = Mathf.Sin (Time.time) * Time.deltaTime;
particles*.position += Vector3 (0, yPosition, 0);*
*```*
*<p>to something like:</p>*
*```*
*// Randomize x position*
*var xPosition = Random.Range(0, 10);*
_particles*.position += Vector3 (xPosition, 0, 0);*_
_*```*_
_*<p>Note: If the only thing you want to do is randomize starting position of the particles, you may want to consider (instead of your script) editing the <a href="http://unity3d.com/support/documentation/Components/class-EllipsoidParticleEmitter.html" rel="nofollow">particle emitter</a> to get the same effect. For example, you can make the standard ellipsoid emitter long along the X-axis and get random particles that way.</p>*_