Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added lightning bolt looking energy transfer effects.
- Loading branch information
1 parent
0cd3ac2
commit 0d2b6d7
Showing
38 changed files
with
696 additions
and
3 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
This script is placed in public domain. The author takes no responsibility for any possible harm. | ||
Contributed by Jonathan Czeck | ||
*/ | ||
using UnityEngine; | ||
using System.Collections; | ||
|
||
public class LightningBolt : MonoBehaviour | ||
{ | ||
public Transform target; | ||
public int zigs = 100; | ||
public float speed = 1f; | ||
public float scale = 1f; | ||
public Light startLight; | ||
public Light endLight; | ||
|
||
Perlin noise; | ||
float oneOverZigs; | ||
|
||
private Particle[] particles; | ||
|
||
void Start() | ||
{ | ||
oneOverZigs = 1f / (float)zigs; | ||
particleEmitter.emit = false; | ||
|
||
particleEmitter.Emit(zigs); | ||
particles = particleEmitter.particles; | ||
} | ||
|
||
void Update () | ||
{ | ||
if (noise == null) | ||
noise = new Perlin(); | ||
|
||
float timex = Time.time * speed * 0.1365143f; | ||
float timey = Time.time * speed * 1.21688f; | ||
float timez = Time.time * speed * 2.5564f; | ||
|
||
for (int i=0; i < particles.Length; 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), | ||
noise.Noise(timey + position.x, timey + position.y, timey + position.z), | ||
noise.Noise(timez + position.x, timez + position.y, timez + position.z)); | ||
position += (offset * scale * ((float)i * oneOverZigs)); | ||
|
||
particles[i].position = position; | ||
particles[i].color = Color.white; | ||
particles[i].energy = 1f; | ||
} | ||
|
||
particleEmitter.particles = particles; | ||
|
||
if (particleEmitter.particleCount >= 2) | ||
{ | ||
if (startLight) | ||
startLight.transform.position = particles[0].position; | ||
if (endLight) | ||
endLight.transform.position = particles[particles.Length - 1].position; | ||
} | ||
} | ||
} |
Oops, something went wrong.