- Home /
Emit from Edge in Script
Hi there,
I'm trying to create an "area of effect" particle system that has the particles appear along the border of box shaped location.
Here is my code:
// Set area of effect ring
ParticleSystem particle = GameObject.Find("location").AddComponent<ParticleSystem>();
ParticleSystem.MainModule main = particle.main;
main.startSize = (float)0.5;
ParticleSystem.EmissionModule emission = particle.emission;
switch (location.size_identifier) {
case 'S':
emission.rateOverTime = (float)25;
break;
case 'M':
emission.rateOverTime = (float)50;
break;
case 'L':
emission.rateOverTime = (float)100;
break;
}
particle.GetComponent<ParticleSystemRenderer>().material = new Material((Material)Resources.Load("Materials/Default-Particle"));
particle.GetComponent<ParticleSystemRenderer>().sortingOrder = 1;
ParticleSystem.ShapeModule box = particle.shape;
box.shapeType = ParticleSystemShapeType.Box;
box.enabled = true;
// TRYING TO SET THE VALUE HERE
box.box = new Vector3((float)(location.size * 1.28), (float)(((float)location.size) * 1.28), (float)(((float)location.size) * 1.28));
Everything works fine, I just need to know how to access the "Emit from:" value within the shape module and set it to "Edge" like I can do in the Unity editor. There doesn't seem to be a member variable for this and I'm having trouble finding any info for it online.
Answer by ifurkend · Sep 10, 2017 at 10:43 PM
Old and wrong answer: From Unity 2017.1, boolean "emit from edge" is replaced by the float "thickness" for flexibility, give it zero value and it will behave the same as emitting from edge.
Edit: According to ShapeType API, defining "ParticleSystemShapeType.BoxEdge" should do the trick.
Thank you for your quick response! I went ahead and upgraded to Unity 2017.1 and found the boxThickness variables-- however setting it to zero (or rather, a new Vector3(0,0,0) because it is what it requires) did not seem to do the trick. Any other ideas?
Did you mean particles emitted from a "line of edge" ins$$anonymous$$d of "surface/face" of the box?
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to increase max particles in a particle system against a timer? 0 Answers
How to change the sprite in "texture sheet animation" from three different sprites? 1 Answer
How to force a particle system emit from every vertex a mesh have? 3 Answers