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!! :slight_smile:

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: Unity - Scripting API: MonoBehaviour.StartCoroutine

Good luck! :slight_smile:

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