I’m trying to emit a single particle on each vert of a mesh emitter. the idea is to use this for a muzzle flash effect.
i’ve run into multiple issues.
- I can only get the particles to get positioned on one vert…
- they no longer respect the vert normal for the direction.
- a particle appears in the origin of the system on the first frame…
Anyone got a better method for doing this?
heres the script…
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ParticleSpawnOnMesh : MonoBehaviour {
public Mesh myMesh;
private ParticleSystem ps = null;
// Use this for initialization
void Start()
{
this.ps = this.GetComponent<ParticleSystem>();
var main = ps.main;
var sh = ps.shape;
sh.enabled = true;
sh.shapeType = ParticleSystemShapeType.Mesh;
sh.mesh = myMesh;
main.maxParticles = myMesh.vertexCount;
}
// Update is called once per frame
void Update ()
{
Vector3[] verteces = myMesh.vertices;
if ((this.ps != null) && (this.ps.particleCount != 0))
{
ParticleSystem.Particle[] particles = new ParticleSystem.Particle[this.ps.particleCount];
int count = myMesh.vertexCount;// this.ps.GetParticles(particles);
var emitParams = new ParticleSystem.EmitParams();
for (int i = 0, ic = count; i < ic; i++)
{
emitParams.position = verteces[i];
Debug.Log( verteces[i].ToString("F4"));
}
//emitParams.applyShapeToPosition = true;
ps.Emit(emitParams, count);
}
}
}