I'm having this script, enabling or disabling a component in Update() depending on a bool.
I guess it would be better to just set it once each time the boolean changes, but as I’m still very new to this and time is running short, this appeared to be the easiest solution…
function Update ()
{
if ( !ActivePlayerControll.waschActive)
{
light.enabled = true;
}
else
{
light.enabled = false;
}
}
Question is, since this would be applied to quite a few GOs, is it any draining on the system? (Can't really imagine, but better save than sorry...)
As you said, it would be better to just change it once. It's probably not a HUGE drain, but there shouldn't be any reason to constantly poll/set stuff in Update. I don't know what you're doing exactly, of course, but something along these lines might give you an idea:
// Disable lights in all objects tagged "Foo"
var lightObjects = GameObject.FindGameObjectsWithTag("Foo");
for (object in lightObjects)
object.light.enabled = false;
That could still be optimized further, such as by only doing the Find once and keeping the result, and then only re-doing it if the number of objects tagged "Foo" ever changed.