I have a particle system, which I want to emit at a series of randomly determined points all during the same frame. Through testing, I find that I can simply set pfx.transform.position to the location and the particles will emit there when I call pfx.Emit(n).
However, When trying to make several particles at once in different locations, looping through several times and changing the pfx position before a call to pfx.Emit(1) does not work - they all emit in the first location set. Weird.
Here’s the code I’m using:
// go is a game object var from earlier
Mesh m = go.GetComponent<MeshFilter>().mesh;
int cnt = m.vertices.Length;
int numParts = 10;
for (int i = 0; i < numParts; ++i)
{
Vector3 vpos = m.vertices[(int)(math.FRand() * cnt)];
// p is a ParticleSystem object
p.transform.position = go.transform.TransformPoint(vpos);
Debug.Log("vpos " + vpos + " tranforms into " + go.transform.TransformPoint(vpos));
p.Emit(1);
}
The debug I have in there shows me that the transformed positions are all correct, but only the first call to p.transform.position = go.transform.TransformPoint(vpos) seems to have any effect. I think this is perhaps something to do with needing to update a frame first? I’ve used similar code before to make trails on moving objects, but they emit in one place per frame, not several places at once.
Has anyone experienced this or know a way around it?