// Use this for initialization void Start() { Num = 2000; minradius = 5f; maxradius = 10f; speed = 8f; particle = new ParticleSystem.Particle[Num]; particleMes = new ParticleMes[Num]; particleSys = this.GetComponent <ParticleSystem>(); particleSys.maxParticles = Num; particleSys.Emit(Num); particleSys.GetParticles(particle); for (int i = 0; i < Num; i++) { float midRadius = (minradius + maxradius) / 2; float radiusrate = Random.Range(1.0f, midRadius / minradius); float rate = Random.Range(midRadius / maxradius, 1.0f); float radius = Random.Range(minradius * radiusrate, maxradius * rate); float angle = Random.Range(0.0f, 360.0f); float alpha = angle / 180 * Mathf.PI; particleMes[i] = new ParticleMes(radius, angle); particle[i].position = new Vector3(particleMes[i].radius * Mathf.Cos(alpha), 0f, particleMes[i].radius * Mathf.Sin(alpha)); } particleSys.SetParticles(particle, Num); }
public float speed; //速度 // Use this for initialization void Start() { particleNum = 1000; min = 6f; max = 9f; speed = 5f; // 初始化粒子数组 particle = new ParticleSystem.Particle[particleNum]; particleMes = new ParticleMes[particleNum]; // 初始化粒子系统 particleSys = this.GetComponent <ParticleSystem>(); particleSys.startSpeed = 0; //粒子位置由程序控制 particleSys.startSize = 0.03f; //设置粒子大小 particleSys.loop = true; //不断循环 particleSys.maxParticles = particleNum; //设置粒子量 particleSys.Emit(particleNum); //发射粒子 particleSys.GetParticles(particle); for (int i = 0; i < particleNum; ++i) { //粒子位置在内外径之内 float midRadius = (min + max) / 2; float minRate = Random.Range(1.0f, midRadius / min); float maxRate = Random.Range(midRadius / max, 1.0f); float radius = Random.Range(min * minRate, max * maxRate); //角度 float angle = Random.Range(0.0f, 360.0f); float theta = angle / 180 * Mathf.PI; particleMes[i] = new ParticleMes(radius, angle); particle[i].position = new Vector3(particleMes[i].radius * Mathf.Cos(theta), 0f, particleMes[i].radius * Mathf.Sin(theta)); } particleSys.SetParticles(particle, particleNum); }