Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Lightning effect

Discussion in 'Scripting' started by chclau, May 4, 2011.

  1. chclau

    chclau

    Joined:
    Apr 4, 2011
    Posts:
    20
    I have searched for this and I was not successful.

    Has anybody made a lightning / electric arc effect, using assets and/or scripting?
     
  2. Zogg

    Zogg

    Joined:
    Mar 28, 2009
    Posts:
    157
    Some time ago I made a "electro shock weapon" effect which worked like this : It was basically a rectangle with the Particles/Additive shader and a "lighting" texture which changed randomly. The texture looked like this :



    The rectangle actually showed only 1/8 of the texture, it's x offset changed randomly with the following script :

    Code (csharp):
    1.  
    2. var mfMinInterval : float;
    3. var mfMaxInterval : float;
    4. var mvOffset = Vector2( 0.125, 0.0 );
    5.  
    6. private var mfTimer = 0.0;
    7.  
    8. function Update ()
    9. {
    10.     mfTimer -= Time.deltaTime;
    11.     if( mfTimer <= 0.0 )
    12.     {
    13.         mfTimer = Random.Range( mfMinInterval, mfMaxInterval );
    14.         renderer.material.mainTextureOffset += mvOffset;
    15.     }
    16. }
    17.  
    where mfMinInterval and mfMaxInterval define the minimal and maximal delay between texture changes.

    To find tutorials on how to create the lighning bolts, search "lightning photoshop" in Google.
     
  3. RoyS

    RoyS

    Joined:
    Jan 12, 2009
    Posts:
    664
  4. Tom163

    Tom163

    Joined:
    Nov 30, 2007
    Posts:
    1,290
  5. chclau

    chclau

    Joined:
    Apr 4, 2011
    Posts:
    20
    Wow, this is really great

    Thank you all, I hope to use this solutions soon
     
  6. jjxtra

    jjxtra

    Joined:
    Aug 30, 2013
    Posts:
    1,464