- Home /
Question by
jdurc · Mar 05, 2013 at 10:53 PM ·
javascriptfunctionflickeringunderwater
Underwater effect function causing screen flickering
I just wrote a very basic script which adds a fog and colour change effect to the main camera when the player goes underwater (at roughly Y 19). The script works fine, however; whenever the play goes near that Y position (from about 25 and lower) the screen flickers between normal and underwater effect. This is clearly quite a problem when on any low parts of my terrain, and I don't understand why it would happen as the script is really quite simple.
var fog = true;
var fogColor = Color (0, 0.4, 0.9, 0.8);
var fogDensity = 0.90;
function Update () {
if (transform.position.y < 19.0){
RenderSettings.fog = fog;
RenderSettings.fogColor = fogColor;
RenderSettings.fogDensity = fogDensity;
}
else{
RenderSettings.fog = false;
RenderSettings.fogDensity = 0.00;
}
}
The flickering does not happen when this script it disabled, so it's definitely the part of my game which is at fault. Let me know if you guys need any more details to help me. Thanks in advance.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613093901im_/https://answers.unity.com/themes/thub/images/avi.jpg)