Commit 3f55e113 authored by mercury233's avatar mercury233

fix LightningBolt unity ParticleSystem

parent 6f0d3cbd
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
*/ */
using UnityEngine; using UnityEngine;
using System.Collections; using System.Collections;
using static UnityEngine.ParticleSystem;
public class LightningBolt : MonoBehaviour public class LightningBolt : MonoBehaviour
{ {
public Transform target; public Transform target;
...@@ -15,17 +16,20 @@ public class LightningBolt : MonoBehaviour ...@@ -15,17 +16,20 @@ public class LightningBolt : MonoBehaviour
public Light endLight; public Light endLight;
Perlin noise; Perlin noise;
float oneOverZigs; float oneOverZigs;
// private Particle[] particles; private ParticleSystem ps;
private Particle[] particles;
void Start() void Start()
{ {
oneOverZigs = 1f / (float)zigs; oneOverZigs = 1f / (float)zigs;
// GetComponent<ParticleEmitter>().emit = false; ps = GetComponent<ParticleSystem>();
particles = new Particle[zigs];
// GetComponent<ParticleEmitter>().Emit(zigs); var em = ps.emission;
// particles = GetComponent<ParticleEmitter>().particles; em.enabled = false;
ps.Emit(zigs);
ps.GetParticles(particles);
} }
void Update () void Update ()
...@@ -35,29 +39,29 @@ public class LightningBolt : MonoBehaviour ...@@ -35,29 +39,29 @@ public class LightningBolt : MonoBehaviour
float timex = Time.time * speed * 0.1365143f; float timex = Time.time * speed * 0.1365143f;
float timey = Time.time * speed * 1.21688f; float timey = Time.time * speed * 1.21688f;
float timez = Time.time * speed * 2.5564f; float timez = Time.time * speed * 2.5564f;
// for (int i=0; i < particles.Length; i++) for (int i = 0; i < particles.Length; i++)
// { {
// Vector3 position = Vector3.Lerp(transform.position, target.position, oneOverZigs * (float)i); Vector3 position = Vector3.Lerp(transform.position, target.position, oneOverZigs * (float)i);
// Vector3 offset = new Vector3(noise.Noise(timex + position.x, timex + position.y, timex + position.z), Vector3 offset = new Vector3(noise.Noise(timex + position.x, timex + position.y, timex + position.z),
// noise.Noise(timey + position.x, timey + position.y, timey + position.z), noise.Noise(timey + position.x, timey + position.y, timey + position.z),
// noise.Noise(timez + position.x, timez + position.y, timez + position.z)); noise.Noise(timez + position.x, timez + position.y, timez + position.z));
// position += (offset * scale * ((float)i * oneOverZigs)); position += (offset * scale * ((float)i * oneOverZigs));
//
// particles[i].position = position; particles[i].position = position;
// particles[i].color = Color.white; particles[i].startColor = Color.white;
// particles[i].energy = 1f; //particles[i].energy = 1f;
// } }
//
// GetComponent<ParticleEmitter>().particles = particles; ps.SetParticles(particles);
//
// if (GetComponent<ParticleEmitter>().particleCount >= 2) if (ps.particleCount >= 2)
// { {
// if (startLight) if (startLight)
// startLight.transform.position = particles[0].position; startLight.transform.position = particles[0].position;
// if (endLight) if (endLight)
// endLight.transform.position = particles[particles.Length - 1].position; endLight.transform.position = particles[particles.Length - 1].position;
// } }
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment