Search Unity

Change the color of particles on one side

Discussion in 'Scripting' started by Mike L, Apr 6, 2011.

  1. Mike L

    Mike L

    Joined:
    Sep 14, 2010
    Posts:
    1,035
    how can you change the color of particles on one part of a particle system, like shadows on the bottom of a cloud?
     
  2. Satoh

    Satoh

    Joined:
    Feb 17, 2011
    Posts:
    56
    hmmm... that's an interesting concept. What I would try, is rather than changing the particles colors, use a particle texture that has the shadow on it and play with the blending mode options. I'll think about it some more and give you some other ideas if I come up with any.
     
  3. Mike L

    Mike L

    Joined:
    Sep 14, 2010
    Posts:
    1,035
    ok, how would i do that? and what about these UV animations on the particle renderer?
     
  4. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
  5. Mike L

    Mike L

    Joined:
    Sep 14, 2010
    Posts:
    1,035
    well, i cant use anything pre-made, because were going to sell this
     
  6. bigmisterb

    bigmisterb

    Joined:
    Nov 6, 2010
    Posts:
    4,221
    This is actually fairly simple.

    Create an emitter. That is your "cloud".
    Create a Bounds
    Set the Bounds Max and Min to the emitter position.
    Roll through all the particles.
    use the Mathf.Min(Bounds.min, ParticleEmitter.particles.position) and Mathf.Max(Bounds.max, ParticleEmitter.particles.position) to set your bounds.
    This gives you a Bounds.size.y, a Bounds.center.y+Bounds.extents.y and Bounds.center.y-Bounds.extents.y

    Now just roll through the particles again, and check where they sit top to bottom.
    Adjust the color of each particle using ParticleEmitter.particles.color to the Color.Lerp(bottomColor, topColor, (ParticleEmitter.particles.position.y - BoundsMin) / (BoundsMax-BoundsMin))

    Tada, volumetric cloud.... ;)