Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by user-7337 (google) · Jan 15, 2011 at 12:15 AM · lightningflashinginterval

Lightning flash

I need a full script that can flash a light at random intervals for lightning simple as that

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
5
Best Answer

Answer by DaveA · Jan 15, 2011 at 01:13 AM

This is a real quick idea, you'll want to play with the numbers, but you should get the ideas. Attach to a DirectionalLight I would think.

var minTime = .5; var thresh = .5;

private var lastTime = 0; private var myLight;

function Start() { myLight = GetComponent(Light); }

function Update () {

 if ((Time.time - lastTime) > minTime)
     if (Random.value > thresh)
         light.enabled = true;
     else
         light.enabled = false;
 lastTime = Time.time;

}

thresh is the minimum threshold between 0 and 1 that a random number must exceed to turn the light on. minTime is the minimum time interval to check that random number.

A more realistic effect might have a 'strike check' time (between 'strikes') and each strike would be 'on' for some small amount of time, during which rapid flashing would take place. I'll leave that to you.

Comment
Add comment · Show 11 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DaveA · Jan 15, 2011 at 01:41 AM 0
Share

Here are some more ideas: http://answers.unity3d.com/questions/14505/lightning-with-random-intervals

avatar image user-7337 (google) · Jan 15, 2011 at 08:14 PM 0
Share

You are my hero...works flawlessly :)

avatar image Deeweext · Feb 05, 2013 at 08:55 PM 0
Share

How memory intensive, is this approach? As in toggling enabling this fast, this often? And creds for provindg a full script to the poster.

avatar image coward · Jul 29, 2013 at 06:29 AM 1
Share

STARS - use a single manager script to handle the ti$$anonymous$$g and tell the lights that subscribe to the change to change their enabledness when they are told to by the manager

avatar image DaveA · Jul 29, 2013 at 06:46 AM 1
Share

STARS - make myLight an array of lights and assign the lights that need to be on/off at the same time to the array. Then when turning on/off, iterate through the array setting 'enabled' for all of them.

Show more comments
avatar image
0

Answer by dazzsnow · Oct 25, 2013 at 04:20 AM

Here is a java script for Lightning and Thunder.

 public var offMin : float= 10;
 public var offMax : float= 60;
 public var onMin : float=0.25;
 public var onMax : float= 0.8;
 public var l : Light;
 public var Thunder : AudioClip[];
 
 
 function Start() 
 {
 light();
 }
 
 function light()
 {
     while(true)
         {
         yield WaitForSeconds(Random.Range(offMin, offMax));
         l.enabled = true;
         soundfx();
         yield WaitForSeconds(Random.Range(onMin, onMax));
         l.enabled = false;
         }
 }
 
 function soundfx()
 {
     yield WaitForSeconds(Random.Range(0.25,1.75));
     audio.PlayOneShot(Thunder[Random.Range(0,Thunder.Length)]);
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Flashes of light 0 Answers

How do i spawn a square in random position within an area but only at certain x and y intervals? 1 Answer

Random Array of sounds for Random Game Object 1 Answer

Adding a collider to a lightning script that has a constantly changing size 0 Answers

My gameObject starts flashing 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges