Lightning Bolt 2D
Lightning Bolt 2D is a geometry-based electric charge or lightning effect for your 2D Unity projects.Features
- Simple to use and configure. Set colors, width, distortion and more to achieve exactly what you need
- Geometry-based. No sprites used, resizing doesn't cause image stretching
- Well commented code with every property explained, easy to integrate into your project
- Works on mobile
- Works in UI
- Supports sprite sorting layers
How to use?
After you've imported this asset, to start using it click Game Object > Effects > Lightning Bolt 2D in Unity's main menu. Or do the same by right-clicking the Hierarchy panel. This will add a new Lightning Bolt 2D object to your scene.
After this you can hit play and see it in action right away.
Settings
Arc count sets how many lines will be drawn.
Point count sets how many points each line has.
Line color, line width, glow color and glow width determine line and glow thickness and colors.
Distort sets the value that will randomly offset points of the line.
Jitter is basically the same but per-frame. It's only visible when effect is playing.
Bend amount sets how hard the line will be initially curved when it's generated.
Bend speed sets how much it will curve during playback.
There's also an FPS Limit if you only want to limit how many times per second this object is allowed to be recalculated and redrawn.
Playback options are there to let you turn this effect on and off.
If you set it to off, and if you're scene is in play mode, you can click Fire once to generate the effect and let it play out without generating it continuosly.
Regenrate lets you recalculate effect using new random valuer. It's there to be able to see differently-randomized lightnings in edit mode.
Keep in mind
Increasing number of lightnings and number of points increases the number of calculation script has to do every second. Setting them to very high values can decrease performance of your game.
How to use in code
It's easy to access all the settings in runtime. Here's an example:
//Change positions of start and end points
LightningBolt2D.startPoint=new Vector2(-8f,5f);
LightningBolt2D.endPoint.y=-6f;
//How to change settings
LightningBolt2D.lineWidth=0.4f;
LightningBolt2D.lineColor=Color.white;
LightningBolt2D.distort=0.02f;
//Stop object from generating new lightnings
LightningBolt2D.isPlaying=false;
//Generate lightnings once, based on your configuration
LightningBolt2D.FireOnce();
Every value you see in inspector can be modified at runtime. To see the full list of variable names refer to the source code of the asset.
If you like this asset, please consider giving it a rating or a short review on the Asset Store. This will help others to discover it and make sure I'll keep improving it.