Best way to make blinking light
Hello!!!
I know how to make a point light fliker/blink. What I am asking is the best way in terms of rendering. I mean should I use the enable bool, or the range/intensity float? Which one is easiest for unity to render?
Also by fast I mean really fast, I am using this light as the muzzle flash of a gun. If you know a better way to make this flashing feel free to tell me!
Thanks in advance!! :)
Answer by ComradeVanti · Mar 19, 2016 at 02:07 PM
Im pretty sure a plain boolean would do a rescource-friendly job but it might not look as good as a intensity-changer.
If you want to change the intensity smoothly try something like this:
using UnityEngine;
using System.Collections;
public class Flash : MonoBehaviour
{
public float totalSeconds; // The total of seconds the flash wil last
public float maxIntensity; // The maximum intensity the flash will reach
public Light myLight; // Your light
public IEnumerator flashNow ()
{
float waitTime = totalSeconds / 2;
// Get half of the seconds (One half to get brighter and one to get darker)
while (myLight.intensity < maxIntensity) {
myLight.intensity += Time.deltaTime / waitTime; // Increase intensity
yield return null;
}
while (myLight.intensity > 0) {
myLight.intensity -= Time.deltaTime / waitTime; //Decrease intensity
yield return null;
}
yield return null;
}
}
As you can see this method is a CoRoutine. If you are not familiar with them check this link: http://docs.unity3d.com/ScriptReference/MonoBehaviour.StartCoroutine.html
Good luck! :)
Thank you very much and especially for expanding your answer with your script! I used a timer, that I used for the guns fire rate, with a Lerp function to change the intecity.
Answer by briandcruz67 · Mar 16, 2017 at 03:33 AM
Hi Brullix3000
How can i get this script to work with a strip of lights in an array so each light comes on then goes off one bt one down the array.. like a Christmas lights sequencer with color variations
Regards Brian