Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Start ()
- {
- myBase = gameObject.GetComponent<OrbBase>();
- emitter = (GameObject)Instantiate(ParticlePrefab);
- emitter.transform.parent = this.transform;
- emitter.transform.position = transform.position;
- myParticles = new List<RotateParticleFinal>();
- myRemovedParticles = new List<RotateParticleFinal>();
- for (int i=0; i < myBase.Particles; i++)
- {
- float r = GetNewRadius();
- myParticles.Add(new RotateParticleFinal(r, color));
- }
- }
- void Update ()
- {
- #region Deal with changing particle count
- while (myParticles.Count < myBase.Particles)
- {
- float r = GetNewRadius();
- myParticles.Add(new RotateParticleFinal(r, color));
- }
- for (int i=myParticles.Count-1; i >= 0; i--)
- {
- if (myParticles[i].Dead)
- myParticles.RemoveAt(i);
- }
- while (myParticles.Count > myBase.Particles)
- {
- myParticles.RemoveAt(myParticles.Count-1);
- }
- #endregion
- //TODO: Do we really want 5000? Can the number change to match our base particle count?
- ParticleSystem.Particle[] tempParticles = new ParticleSystem.Particle[5000];
- int count = emitter.GetComponent<ParticleSystem>().GetParticles(tempParticles);
- for (int i=0; i < count; i++)
- {
- if (i >= myBase.Particles)
- {
- //This is more than we want, destroy it immediately and make sure that we don't get more than we really want.
- tempParticles[i].lifetime = -1;
- }
- else
- {
- myParticles[i].Update();
- if (tempParticles[i].lifetime < 5)
- {
- //Don't let it die!
- tempParticles[i].lifetime = 1024;
- }
- tempParticles[i].position = myParticles[i].GetPosition();
- //Debug.Log("hi");
- if (myParticles[i].ChangingColors)
- {
- tempParticles[i].color = myParticles[i].MyColor;
- if (tempParticles[i].color.a == 1)
- {
- //This is the only place that ChangingColors is set to false so it should never stop fading in until I've faded all the way in.
- myParticles[i].ChangingColors = false;
- }
- }
- if (!myParticles[i].SetUp)
- {
- //This is a brand new particle, so I need to tell it a few things.
- //We don't want it moving on it's own.
- tempParticles[i].velocity = Vector3.zero;
- tempParticles[i].axisOfRotation = new Vector3(Random.Range(-0.1f, 0.1f), Random.Range(-0.1f, 0.1f));
- myParticles[i].SetUp = true;
- }
- }
- }
- emitter.GetComponent<ParticleSystem>().SetParticles(tempParticles, count);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement