Advertisement
Guest User

Untitled

a guest
Jul 28th, 2015
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. void Start ()
  2. {
  3. myBase = gameObject.GetComponent<OrbBase>();
  4.  
  5. emitter = (GameObject)Instantiate(ParticlePrefab);
  6. emitter.transform.parent = this.transform;
  7. emitter.transform.position = transform.position;
  8.  
  9. myParticles = new List<RotateParticleFinal>();
  10. myRemovedParticles = new List<RotateParticleFinal>();
  11.  
  12. for (int i=0; i < myBase.Particles; i++)
  13. {
  14. float r = GetNewRadius();
  15. myParticles.Add(new RotateParticleFinal(r, color));
  16. }
  17. }
  18.  
  19. void Update ()
  20. {
  21. #region Deal with changing particle count
  22. while (myParticles.Count < myBase.Particles)
  23. {
  24. float r = GetNewRadius();
  25. myParticles.Add(new RotateParticleFinal(r, color));
  26. }
  27.  
  28. for (int i=myParticles.Count-1; i >= 0; i--)
  29. {
  30. if (myParticles[i].Dead)
  31. myParticles.RemoveAt(i);
  32. }
  33.  
  34. while (myParticles.Count > myBase.Particles)
  35. {
  36. myParticles.RemoveAt(myParticles.Count-1);
  37. }
  38. #endregion
  39.  
  40.  
  41. //TODO: Do we really want 5000? Can the number change to match our base particle count?
  42. ParticleSystem.Particle[] tempParticles = new ParticleSystem.Particle[5000];
  43. int count = emitter.GetComponent<ParticleSystem>().GetParticles(tempParticles);
  44.  
  45. for (int i=0; i < count; i++)
  46. {
  47. if (i >= myBase.Particles)
  48. {
  49. //This is more than we want, destroy it immediately and make sure that we don't get more than we really want.
  50. tempParticles[i].lifetime = -1;
  51. }
  52. else
  53. {
  54. myParticles[i].Update();
  55. if (tempParticles[i].lifetime < 5)
  56. {
  57. //Don't let it die!
  58. tempParticles[i].lifetime = 1024;
  59. }
  60.  
  61. tempParticles[i].position = myParticles[i].GetPosition();
  62.  
  63. //Debug.Log("hi");
  64.  
  65. if (myParticles[i].ChangingColors)
  66. {
  67. tempParticles[i].color = myParticles[i].MyColor;
  68. if (tempParticles[i].color.a == 1)
  69. {
  70. //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.
  71. myParticles[i].ChangingColors = false;
  72. }
  73. }
  74.  
  75.  
  76. if (!myParticles[i].SetUp)
  77. {
  78. //This is a brand new particle, so I need to tell it a few things.
  79. //We don't want it moving on it's own.
  80. tempParticles[i].velocity = Vector3.zero;
  81. tempParticles[i].axisOfRotation = new Vector3(Random.Range(-0.1f, 0.1f), Random.Range(-0.1f, 0.1f));
  82. myParticles[i].SetUp = true;
  83. }
  84. }
  85. }
  86. emitter.GetComponent<ParticleSystem>().SetParticles(tempParticles, count);
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement