- Home /
Appear and Dissapear: Fog
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:)
Answer by aldonaletto · Oct 11, 2013 at 09:59 AM
You could deactivate the fog with a script like this (attach it to the Fog game object):
function OnTriggerEnter(other: Collider){
if (other.CompareTag("noFog")){ // if entering trigger tagged "noFog"...
gameObject.SetActive(false); // auto deactivate
}
}
function OnTriggerExit(other: Collider){
if (other.CompareTag("noFog")){ // exiting trigger "noFog":
gameObject.SetActive(true); // auto re-activate
}
}
NOTE: Remember to set the trigger tag to "noFog" (you must register this tag before using it).
If the resulting effect is too hard (fog disappears/appears too suddenly), you can stop the particle emitter instead of deactivating the whole object:
function OnTriggerEnter(other: Collider){
if (other.CompareTag("noFog")){ // if entering trigger tagged "noFog"...
particle.emit = false; // turn particle emitter off
}
}
function OnTriggerExit(other: Collider){
if (other.CompareTag("noFog")){ // exiting trigger "noFog":
particle.emit = true; // turn on particle emitter
}
}
Your answer
Follow this Question
Related Questions
Fog On and Off Script Help! 2 Answers
Gradually change distance fog over time with a collider object. 1 Answer
OnMouseDown() with a Mesh Collider? 2 Answers
Collision, tags, and triggers 1 Answer
Collision flag entering a tagged object's collider 2 Answers