Fog On and Off Script Help!

So i have a working Fog effect on my project attached to the player so it moves where the player goes. The thing is that the fog should not follow my player inside the buildings in my scene(because there is no fog inside my buildings). So I was wondering is there is some way to make a script that i can attach to some colliders that I will put in every enter/exit door of my buildings that turn the fog on and off, so when i enter the building the fog turns off and if I go out again, on (something like Fog OnTriggerEnter maybe??). Some script that turn this on and off:


Is there a way??, my fog is untagged… Should I create a tag for the fog? (For example—> Tag: TheFog)

Please help:)

Well, for starters, you could block out the buildings with some cube primitives, turn of the mesh renderers and check the “Is Trigger” boolean in the “Box Collider” component.

Then, you could use the cube’s OnTriggerEnter() and OnTriggerExit() functions (void OnTriggerEnter(Collider other){ in C#, function OnTriggerEnter(other : Collider){ in java)

The object the just entered the trigger zone is in that function known as “other”. So, we can check for tags (for instance “player” or “fog”) ( this would look like if(other.tag == "tag"){), and turn off the particle emitter entirely (other.gameObject.GetComponent("ParticleRenderer").active = false; should work).

You might want to consider just using scene fog, since you don’t have to use GetComponent() if you do (it’s RenderSettings.fog = true; instead).

I hope this solves it for you. If you’re still stuck, you can contact me via Steam.


De Yuang Ann Wijning


public GameObject Fog; //declare this variable and drag your Fog object into it in the editor.

Fog.setActive(false); woud be the collider code for entering a building.
Fog.setActive(true); would be for exiting a building.

You might put two triggers next to each other in each door, so that you have an enter and exit collider.