Pulling a Boolean from one script to fuel another script

Hello all,

Been kicking around some script, and realized I made a huge error.

I have a script that toggles a Night Vision Goggle effect on the player camera, which does the normal green tint and grain effect. I also had a script that would be applied to all the light sources that would multiply their intensity whenever the player toggled the Goggles. As a result, whenever you turned on the NVGs, looking at a candle would be like looking at a 100 watt bulb, and looking at a campfire would be like glaring into the sun. Unfortunately, I took a lot of possibilities for granted when I set this up. See, the only thing I did was include a getbuttondown statement in the player camera that would toggle the effect, and the same getbuttondown statement in all the lights. I was simply assuming that whenever the level would start, the NVGs would always be off, so everybody would be on the same page. Unfortunately I’ve since given the player the ability to drop a flare. By instantiating a prefab I now have a light in the scene that may not be on the same page as everybody else. Hence, hitting the “N” button can make the flare much brighter when you’re in the dark, and nearly invisible with the NVGs on. Not at all what I want, particularly when making some details completely invisible without NVGs (IR Strobes now work 180 degrees from how they should).

I’m trying to change the matter of fact “NightVision = false” in my lights start function, into something that pulls the same boolean statement from the NightVision toggle script itself. I’m not entirely sure of the terminology for such a thing, but have to imagine that an instantiated object pulling from a script on the first frame of it’s existance has got to be more efficient than the NightVision toggle script running a find and sendmessage every frame of the update function to every gameobject in the scene.

Any help would be appreciated, it would seem like this would be one of those fairly simple problems that would be very important to learn before getting too deep into the rabbit hole. Thanks in advance,

You need to get the reference to the script in memory to access is variables.

I suggest tagging all the objects that you want to have the night vision effecting, as this would seem a more legit way of doing it?

~ Alex

Tags are overused. When you instantiate a new light, use its awake method to find the state it should use. Otherwise I would recommend either an event or the light control to keep a list of light objects which should be categorized by either type or an interface.

Also the light intensity is more of a rendering thing and could probably be done in a more robust camera class.

This is precisely what I’m hoping to do, just using it’s awake function for it to get on the same page as everybody else at least. Whats a good command to look into doing this?

When its awoken, just use a findobjectoftype.