- Home /
Delay on thunderlight
I just copied a code from this forum and now i want some delay between the lightnings.
I've tried to google it and find answers here but nothing works.
var minTime = .5;
var thresh = .5;
private var lastTime = 0;
private var myLight;
function Start()
{
myLight = GetComponent(Light);
}
function Update ()
{
if ((Time.time - lastTime) > minTime)
if (Random.value > thresh)
light.enabled = true;
else
light.enabled = false;
lastTime = Time.time;
}
Anyone who knows how to fix the delay?
Thx!
if you need a delay or time in Unity, just use Invoke()
there is a massive explanation here ... unityGE$$anonymous$$S.com
Answer by Hybris · Oct 30, 2012 at 03:50 PM
You can use Invoke() or InvokeRepeating(), as Fattie said. Invoke(functionname, time; and InvokeRepeating(functionname, delay);
Answer by rejwan1 · Oct 30, 2012 at 04:33 PM
Not exactly what you asked, but here's an old lightning code I've written a few years ago. Simply attach it to a directional light you want to be used as your "lightning" and configure it as you see fit.
Answer by Mtts · Oct 31, 2012 at 09:28 AM
Hey all, thanks for your replies.
I must say, im still kida confused about this invoke()-thing.
How do I use it in the code above?
USING THE INTERNET, CLIC$$anonymous$$ THIS LIN$$anonymous$$
THERE IS A $$anonymous$$ASSIVE, $$anonymous$$ASSIVE EXPLANATION THERE
NO NEED TO COPY AND PASTE IT TO HERE ! :)
YES, I WONDER WHY THEY HAVE THIS FORU$$anonymous$$ HERE WHEN THERE'S GOOGL$$anonymous$$ NO NEED TO COPYPASTE ANYTHING. Sry for caps.
Syntax: Invoke("Function Name", delayInSeconds);
Example: Invoke("Thunder", 3) - Will call the Thunder function in 3 seconds. If you want to repeat the call - InvokeRepeating("Thunder", 2, 0.3f); - This will call Thunder every 0.3 seconds, with an initial delay of 2 seconds, to stop it - CancelInvoke("Thunder")
http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$onoBehaviour.InvokeRepeating.html
http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$onoBehaviour.Invoke.html
And again, I suggest you use the script I've attached in my answer, it does a pretty nice job of lightning and even supports thunder sounds.
Your answer
Follow this Question
Related Questions
Lightning and Thunder Script System 1 Answer
Couple of questions regarding instantiate delays 1 Answer
Delay between each instantiation 3 Answers
Yield only working once? 0 Answers