Red Pulsating Light - Controllable Time

Hi Guys,
I have created an asteroid that is meant to be like a communication station, so I have a tower and I want to add a flashing red light to the top. I have never really had any experience with lighting until now, and I need help. How can I make it flash, like a point light or something that goes off for a second and comes on for a second, but is slow going on and off, like a transition. Please help. I have no scripts created but if I do make one, it will be named: “cTowerLightFlash” if you must know. I will be as helpful as possible. Thanks in advance for any help.

Whutchison

Posted with the wrong account the first time, sorry.

If you want it to simply turn off and on, you could just enable and disable the light:

using UnityEngine;
public class cTowerLightFlash : MonoBehaviour {
	private Light myLight;
	public float pulseSpeed = 1f; //this is in seconds
	private float timer;
	
	void Start(){
		myLight = GetComponent<Light>();
	}	
	void Update(){
		timer += Time.deltaTime;
		if(timer > pulseSpeed){
			timer = 0;
			myLight.enabled =  !myLight.enabled;
		}
	}
}

If you want it to fade in and out, you could modify the intensity variable:

using UnityEngine;
public class cTowerLightFlash : MonoBehaviour {
	private Light myLight;
	public float maxIntensity = 1f;
	public float minIntensity = 0f;
	public float pulseSpeed = 1f; //here, a value of 0.5f would take 2 seconds and a value of 2f would take half a second
	private float targetIntensity = 1f;
	private float currentIntensity;	
	
	
	void Start(){
		myLight = GetComponent<Light>();
	}	
	void Update(){
		currentIntensity = Mathf.MoveTowards(myLight.intensity,targetIntensity, Time.deltaTime*pulseSpeed);
		if(currentIntensity >= maxIntensity){
			currentIntensity = maxIntensity;
			targetIntensity = minIntensity;
		}else if(currentIntensity <= minIntensity){
			currentIntensity = minIntensity;
			targetIntensity = maxIntensity;
		}
		myLight.intensity = currentIntensity;
	}
}

Just put the one you want in a C# script and put that on the light’s gameobject

When you write about a “communication station,” I visualize a light that is seen rather than a light that casts light into the scene. With that in mind, you likely want to use a texture rather than a light. So to implement:

  • Import the texture below. Use import settings that preserve transparency. I used ‘Texture Type’ Advanced, and ‘Format’ as RGBA 32 bit.
  • Add the UnlitAlphaWithFade shader to your project.
  • Create a new material. Set the shader to UnlitAlphaWithFade and the Texture to the one you imported.
  • Create a Quad (GameObject>CreateOther>Quad). If you are using an older version of Unity, you can use the Wiki CreatePlane script.
  • Add the material to the Quad.
  • Add the script below to the Quad.

15643-redlight.png

#pragma strict

var speed = 3.0;
private var color = Color(1,1,1,1);

function Update () {
	transform.rotation = Quaternion.LookRotation(transform.position - Camera.main.transform.position);
	color.a = (Mathf.Sin(Time.time * speed) + 1.0)/2.0;
	renderer.material.color = color;
	
}

Note the code keeps the Quad facing the camera.