- Home /
Change particle size based on how near it is to a given point or height
I am trying to find a way to control the size of individual particles based how close they are to a given point using c#. I have found a few pages that describe the solution I'm looking for. Such as this link here and here.
However, the solutions described in those examples use ParticleSystem.Particle.size
which is obsolete in Unity 2017.
Is it still possible to control the particle size based on where it is in space in Unity 2017?
Answer by richardkettlewell · Apr 02, 2018 at 06:34 PM
Particle.size was replaced with Particle.startSize (as the obsolete script warning message tells you). Simply set that.
Say a Particle System is emitting with a box shape volume. Then particles that are near a given point inside the volume get larger in size. ParticleSystem.main.startSize
seems to be a global value and changes the size of all particles. When I iterate over all particles and use Particle.startSize
nothing changes.
You are setting the results back with SetParticles? Perhaps post some code, as this method is the correct way.
(See https://docs.unity3d.com/ScriptReference/ParticleSystem.GetParticles.html for complete example. simply replace velocity with startSize)
@richardkettlewell Thanks. Replacing velocity with startSize in the link example worked!
Answer by WinterboltGames · Mar 30, 2018 at 06:01 PM
That's quite easy...
public class ParticleSizeChanged : MonoBehavior { public float targetHeight = 25f; public float targetSize = 5f;
private ParticleSystem P_System => GetComponent<ParticleSystem>() ?? default(ParticleSystem);
private void Update ()
{
// you said you want to change the size based on the height only rigth?
var main = P_System.main;
main.startSize.constant = ((transform.position.y / targetHeight) * targetSize);
P_System.main = main;
}
}
Hope this helps...
Thanks @$$anonymous$$illerOfS$$anonymous$$m7, it does change the size but It changes the size for all the particles in the Particle System. What about changing the size of individual particles within the Particle System?
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How Do I Access and Change Items in a List on Another Script? 2 Answers
How can i create array of texture2d with variables names ? 2 Answers
Awesome Bump shader in Unty? 0 Answers