- Home /
Changing the global fog (image effect) color from a different script, possible?
Hi,
This seems like it should be easy but I'm having problems with it. I'm not familiar with the getcomponent so maybe I'm a little off, but here's what I have.
I get the error: Object reference not set to an instance of an object
var fogScript;
GetComponent(GlobalFog);
GetComponent(GlobalFog);
fogScript = GetComponent ("fogMaterial");
fogScript.gameCamera.camera.renderer.fogMaterial.SetColor ("_FogColor", Color.grey);
Answer by save · Mar 07, 2012 at 09:46 AM
I'm not familiar with that post process but your formatting looks a bit messy. Try something like this out:
private var fogScript : GlobalFog;
function Start () { fogScript = GetComponent(GlobalFog); //Camera.main.GetComponent(GlobalFog) if script is not on camera. fogScript.globalFogColor = Color.grey; }
Thanks, but it's the same error I had before. And that is the proper way on calling a material especially when it's attached to the camera. All image effects are, so I would imagine the camera would have to be included.
Any other ways to do this?
Just tried it out and you should use globalFogColor:
fogScript.globalFogColor = Color.grey;
The variables are exposed in all the post process scripts, just have a look inside the files, it won't hurt. ;)
Thank you very much I got it to work, I didn't see the camera.GetComponent.
Answer by LEDWORKS · Mar 15, 2015 at 02:40 PM
This may be new with unity 5, but it now uses RenderSettings.fogColor
Your answer
Follow this Question
Related Questions
.getComponent() creates an Instance? 1 Answer
Object referencing - metafile changes on different computers 1 Answer
How to get material name from instance 3 Answers
After material.SetColor, SetTexture is ignored 1 Answer
Why does gameobject.Find/GetComponent not work when a new scene is loaded? 1 Answer