- Home /
Underwater fog is working but how do I prevent the world fog from turning off?
Hello there
I have a question regarding the turning off/on of fog. I had recently perfected the underwater fog effect for my gaming environment. The fog is restricted within a box collider and is only triggered once a first person controller enters the collider. Upon exit, the underwater fog turns off. However my problem is that my other fog (the fog that spans the whole environment, not the underwater fog) also turns off upon exit. I understand what the problem is but I am unable to bypass it through code since I am relatively new to unity scripting. Note that the underwater fog has a different fog density compared to my "world fog" so deleting my TriggerExit function is not an option. Here is my whole code for the underwater fog. Forgive me if I do not adhere to any code pasting conventions; this is my first post in the forums and it will take time to learn them. Hope you can solve my problems. Thanks in advance
#pragma strict
var fog = false;
var fogColor = Color (0, 0.4, 0.7, 0.6);
var fogDensity = 0.04;
var skybox : Material;
//Function for turning on underwater fog
function OnTriggerEnter(other : Collider) {
if (other.transform.name != "First Person Controller" ) {
fog = false;
}
else {
fog = true;
RenderSettings.fog = fog;
RenderSettings.fogColor = fogColor;
RenderSettings.fogDensity = fogDensity;
RenderSettings.skybox = skybox;
}
}
//Function for switching off underwater fog once the FPS exits the collider
function OnTriggerExit (other : Collider) {
if (other.transform.name != "First Person Controller") {
fog = true;
}
else {
fog = false;
RenderSettings.fog = fog;
}
}
//Snippets for this code acquired from various Unity3d forums
Your answer
![](https://koobas.hobune.stream/wayback/20220613080450im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Individual fog change 0 Answers
Underwater Script 1 Answer
Camera Effect for partially Underwater View 0 Answers
Collision detection between box collider and character controller 1 Answer
underwater fog script 1 Answer