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 Ekta-Mehta-D · Oct 15, 2013 at 07:48 AM · lightinglightthunder

Change Light Color

Hello everyone..

I want to change my light color like blinking effect.. currently by default i have set green color of light.. but when my level starts i want to change my light color at random time in repetitive manner..

example: first time this effect starts after 5 seconds and thet it will start after 10 seconds and in that i want to change light color like green to white for 2-3 times.

So it will be like blinking effect or thunder effect.

But how will i do that? i know how to change the color of light.

I have referred Unity3d documentation.

Code i have written is here :

 #pragma strict
 private var light : GameObject;
 private var done : boolean = false;
 
 function Start () {
     if(!IsInvoking("ThunderEffect"))  
             InvokeRepeating("ThunderEffect",0.01f,5.0f);
 }     
 
 function Update () {
     
 }
 
 function ThunderEffect()
 {
     //GameObject.Find("Directional Light");
     for(var i : int = 0; i < 6 ; i++)
     {
         if(done)
         {
             GameObject.Find("Directional light").light.color = EditorGUIUtility.HSVToRGB(182,255,188);
             yield WaitForSeconds(1.00f);
             done = false;
         }
         else
         {
             GameObject.Find("Directional light").light.color = Color.white;
             yield WaitForSeconds(1.00f);
             done = true;
         }
     }
 }

But this code is not working and even not giving error.

Please help me guys.. Thanks in advance for your support and help..

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 Crystalline · Oct 15, 2013 at 08:01 AM 0
Share

You can try animate it ,or use the Random.range to make it blink when a certain value is available.

1 Reply

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

Answer by clunk47 · Oct 15, 2013 at 04:47 PM

Try something like this. Assign your color array in the inspector for this example.

 #pragma strict
 
 @script RequireComponent(Light);
 
 var colors : Color[];
 var onTime : float;
 var offTime : float;
 
 function Start()
 {
     DoFlicker();
     ChangeTime();
 }
 
 function DoFlicker()
 {
     while(true)
     {
         yield WaitForSeconds(offTime);
         light.enabled = true;
         yield WaitForSeconds(onTime);
         light.color = colors[Random.Range(0, colors.Length)];
         light.enabled = false;
         yield WaitForEndOfFrame();
     }
 }
 
 function ChangeTime()
 {
     while(true)
     {
         yield WaitForSeconds(onTime);
         onTime = Random.Range(0.01f, 0.25f);
         offTime = Random.Range(0.025f, 0.5f);
         yield WaitForEndOfFrame();
     }
 }
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

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

Related Questions

Toggle built in lighting in script 1 Answer

A node in a childnode? 1 Answer

Can't get dynamic shadows working 1 Answer

"Bounces" tick box is greyed out in Lightmapping window? 0 Answers

Lighting Issues with Unity. 2 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