Hi, is it possible to make a script for a light to make it look like an aircraft blinking light?
thank you
Hi, is it possible to make a script for a light to make it look like an aircraft blinking light?
thank you
Yeah, look up WaitForSeconds in a coroutine, and use a bool to command the lights
hmmm, i don’t know how to do that, i pretty young at unity scripting, can you help me please?
thank you
A script would definitely work but why not just a simple looping animation on your light object? Even simpler imo.
i have this simple code and it works:
function Start() {
flickerLight();
}
function Update () {
}
function flickerLight() {
for (var x = 1; x > 0; x++) {
yield WaitForSeconds(2);
gameObject.light.intensity += 10;
yield WaitForSeconds(0.02);
gameObject.light.intensity = 0;
}
}
but i want the light to be off when i press play and then starts to blink
Oop, somebody beat me to it. Oh well, here’s another option that allows for falloff time.
using UnityEngine;
using System.Collections;
public class BlinkingLight : MonoBehaviour {
public float blinkSpeed = 1;
float timer = 0;
float mIntensity;
//Keep this in the 0-1 range in your inspector as the timer only goes from 0-1
public AnimationCurve lightCurve;
void Start () {
mIntensity = light.intensity;
}
void Update () {
timer += Time.deltaTime * blinkSpeed;
if(timer > 1)
timer = 0;
light.intensity = lightCurve.Evaluate(timer);
}
}
Light _light;
public float onTime = 2;
public float offTime = 0.5f;
void Start()
{
_light = transform.light;
Toggle();
}
void Toggle()
{
if(!_light) return;
_light.enabled = !_light.enabled;
if(_light.enabled)
Invoke("Toggle", onTime);
else Invoke("Toggle", offTime);
}