The script you posted by its design is intended to:
- handle ONE light only
- be placed on the GameObject containing that light
- to run indefinitely
If you just need to change a light over time, make an animation and be done with it, no need to code.
Fading, simple and easy:
Otherwise…
Please don’t necro-post. As you can see, your problem is already completely different from the original thread, leading to chaos, confusion and concern by everybody who is now getting pinged by these notices that you replied to their thread.
If you have a new question, make a new post. It’s FREE!!
How to report your problem productively in the Unity3D forums:
This is the bare minimum of information to report:
- what you want
- what you tried
- what you expected to happen
- what actually happened, log output, variable values, and especially any errors you see
- links to actual Unity3D documentation you used to cross-check your work (CRITICAL!!!)
The purpose of YOU providing links is to make our job easier, while simultaneously showing us that you actually put effort into the process. If you haven’t put effort into finding the documentation, why should we bother putting effort into replying?
If you post a code snippet, ALWAYS USE CODE TAGS:
How to use code tags: Using code tags properly
- Do not TALK about code without posting it.
- Do NOT post unformatted code.
- Do NOT retype code. Use copy/paste properly using code tags.
- Do NOT post screenshots of code.
- Do NOT post photographs of code.
- Do NOT attach entire scripts to your post.
- ONLY post the relevant code, and then refer to it in your discussion.