- Home /
Lighting script
I use a script to flicker lights to produce a lighting effect from a thunderstorm. However all my lights flash at different intervals. I tried making it an array of objects and to make them all flash at the same time using this code
var lights: GameObject[];
var flickerSpeed : float = 0.07;
private var randomizer : int = 0;
while (true) {
if (randomizer == 0) {
lights.GetComponent.<Light>().enabled = false;
}
else lights.GetComponent.<Light>().enabled = true;
randomizer = Random.Range (0, 1.1);
yield WaitForSeconds (flickerSpeed);
}
However I get the error
Assets/_Scripts/Flickerv2.js(6,16): BCE0019: 'GetComponent' is not a member of 'UnityEngine.GameObject[]'.
Any help on a way to approach this is appreciated.
Answer by AlucardJay · Mar 31, 2015 at 11:59 AM
lights is an array. You need to specify what gameObject in the array you are trying to access :
lights[ index ].GetComponent.<Light>().enabled = false;
Thank you for the help, I've never used arrays before so I was kinda lost.
Answer by trololo · Mar 31, 2015 at 11:07 AM
Oh yeah... (the guy below is right (and the guy below him seems even righter))
that is incorrect.
// uJS
lights.GetComponent.<Light>().enabled = false;
// C#
lights.GetComponent<Light>().enabled = false;
Your answer
Follow this Question
Related Questions
Extrange Behaviour with 2D Lights in Universal RP 0 Answers
The light is not blending 0 Answers
Prefab asset lights differently in different scenes 0 Answers
Active LIve LIghting 0 Answers
How can I make lighting in scene shine at every part of objects 0 Answers