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 devlord · May 15, 2012 at 04:18 AM · lightinglightflickering

how do i make lights flicker

How can I make 5 point lights flicker on and off so only 1 is on at a time I’m not very good at coding so the easier to understand the better but anything would help.

Thank you all :)

Comment
Add comment · Show 2
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 alpaca of zion · May 15, 2012 at 04:56 AM 0
Share

What do you mean by flicker? Randomly go on and off or some pattern? Is there a time duration? Should they stay the same brightness or change intensity?

avatar image AlucardJay · May 15, 2012 at 04:58 AM 0
Share

make a script that holds the GameObject of each light in a public variable. Then from within the script, access the variable GameObject's Light component, and set to enabled = true/false;

http://unity3d.com/support/documentation/ScriptReference/Light.html

http://unity3d.com/support/documentation/ScriptReference/Behaviour-enabled.html?from=Light

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by alpaca of zion · May 15, 2012 at 08:44 AM

     // Make a list of all of your lights. You can add these in the designer.
     public List<Light> lights = new List<Light>();

     void Update()
     {
         // Run this routine every 100 frames or so. Random.value gives a number between 0 and 1.
         if (UnityEngine.Random.value > .99f)
         {
             // Turn all of the lights off.
             foreach (Light light in lights)
                 light.enabled = false;

             // Turn on one light at random. Random.Range returns a float greater than or equal to 0
             // and less than the count of lights.
             lights[UnityEngine.Random.Range(0, lights.Count)].enabled = true;
         }
     }
Comment
Add comment · Show 4 · 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 hijinxbassist · May 15, 2012 at 08:48 AM 0
Share

elegant solution...ill have to give it a try

avatar image fafase · May 15, 2012 at 08:53 AM 0
Share

I had a similar solution at first using an empty game object and the lights as children then var lights:Component[] and getting the light components of each.

Weirdly I could put them on and off in a foreach loop but would get index out of range if trying to access one particular. Even though I could see them in the inspector. So I went for an easier.

avatar image hijinxbassist · May 15, 2012 at 09:01 AM 0
Share

@alpacaofzion $$anonymous$$akes me wonder though, how are you tally-ing the frames? Do you have a private var counting each frame til the desired frame count is reached? I do like this solution..

avatar image alpaca of zion · May 15, 2012 at 01:59 PM 0
Share

Because this runs in the update function it is called once per frame. It changes the light about every 100 frames, not exactly. The trick is in "if (UnityEngine.Random.value > .99f)" If you wanted to change it 1 in every 5 frames you could use: "if (UnityEngine.Random.value > .80f)". The .80 is because you would be leaving it the same 4/5ths or 80% of the time.

avatar image
0

Answer by Berenger · May 15, 2012 at 05:00 AM

If you want to toggle the lights one after the other at a regular interval, you'll need 1) a function to turn 1 light on and the other off. 2) A loop going through those light with a pause after each iteration. See coroutines.

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

9 People are following this question.

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

Related Questions

Directional light disabling when player is looking away 1 Answer

How to make a GameObject not hittable by shadows ? 2 Answers

Do I still need lightmaps? 1 Answer

How to prevent Overlapping Lights from combining / adding intensity? 3 Answers

[2D] Is it possible to create a collider for 2D lights? 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