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
0
Question by Mtts · Oct 30, 2012 at 11:51 AM · delaylightningthunder

Delay on thunderlight

I just copied a code from this forum and now i want some delay between the lightnings.

I've tried to google it and find answers here but nothing works.

      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;
         
             
     }

Anyone who knows how to fix the delay?

Thx!

Comment
Add comment · Show 1
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 Fattie · Oct 30, 2012 at 01:26 PM 0
Share

if you need a delay or time in Unity, just use Invoke()

there is a massive explanation here ... unityGE$$anonymous$$S.com

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Hybris · Oct 30, 2012 at 03:50 PM

You can use Invoke() or InvokeRepeating(), as Fattie said. Invoke(functionname, time; and InvokeRepeating(functionname, delay);

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
avatar image
0

Answer by rejwan1 · Oct 30, 2012 at 04:33 PM

Not exactly what you asked, but here's an old lightning code I've written a few years ago. Simply attach it to a directional light you want to be used as your "lightning" and configure it as you see fit.

link text


lightning.txt (3.1 kB)
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
avatar image
0

Answer by Mtts · Oct 31, 2012 at 09:28 AM

Hey all, thanks for your replies.

I must say, im still kida confused about this invoke()-thing.

How do I use it in the code above?

Comment
Add comment · Show 3 · 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 Fattie · Oct 31, 2012 at 09:32 AM 0
Share

USING THE INTERNET, CLIC$$anonymous$$ THIS LIN$$anonymous$$

unitygems.com

THERE IS A $$anonymous$$ASSIVE, $$anonymous$$ASSIVE EXPLANATION THERE

NO NEED TO COPY AND PASTE IT TO HERE ! :)

avatar image Mtts · Oct 31, 2012 at 09:44 AM 0
Share

YES, I WONDER WHY THEY HAVE THIS FORU$$anonymous$$ HERE WHEN THERE'S GOOGL$$anonymous$$ NO NEED TO COPYPASTE ANYTHING. Sry for caps.

avatar image rejwan1 · Oct 31, 2012 at 10:01 AM 0
Share

Syntax: Invoke("Function Name", delayInSeconds);

Example: Invoke("Thunder", 3) - Will call the Thunder function in 3 seconds. If you want to repeat the call - InvokeRepeating("Thunder", 2, 0.3f); - This will call Thunder every 0.3 seconds, with an initial delay of 2 seconds, to stop it - CancelInvoke("Thunder")

http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$onoBehaviour.InvokeRepeating.html

http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$onoBehaviour.Invoke.html

And again, I suggest you use the script I've attached in my answer, it does a pretty nice job of lightning and even supports thunder sounds.

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

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Lightning and Thunder Script System 1 Answer

Couple of questions regarding instantiate delays 1 Answer

Delay between each instantiation 3 Answers

Yield only working once? 0 Answers

Autodetect new assets on Mac takes a minute 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