Hi, i’m working on a procedural land generation, and to display the grass, I would like to use ParticleSystem. I’ve searched in every API docs and I can’t figure out why my code would not work with the ParticleSystem.SetParticles() function.
private void SetGrassParticleSystem()
{
ParticleSystem ps = transform.gameObject.AddComponent<ParticleSystem>();
ps.maxParticles = nodes.Count; // = 2601
ps.startSpeed = 0;
ps.startLifetime = float.PositiveInfinity;
ps.enableEmission = false;
ParticleSystem.ShapeModule shape = ps.shape;
shape.shapeType = ParticleSystemShapeType.Sphere;
shape.radius = 100;
ParticleSystemRenderer psr = ps.GetComponent<ParticleSystemRenderer>();
psr.material = SkinBank.GrassMat();
ParticleSystem.Particle[] particles = new ParticleSystem.Particle[nodes.Count];
int i = 0;
foreach(Node node in nodes.Values)
{
particles *= new ParticleSystem.Particle();*
particles*.position = node.Position();*
particles*.startSize = 1;*
particles*.startColor = new Color32(1, 1, 1, 1);*
i++;
}
ps.SetParticles(particles, particles.Length, 0);
}
[148334-help.png|148334]