Why is the following script not working (unity 2021) in my scene? Code (CSharp): using UnityEngine; using System.Collections; public class Underwater: MonoBehaviour { public float waterHeight; private bool isUnderwater; private Color normalColor; private Color underwaterColor; // Use this for initialization void Start () { normalColor = new Color (0.5f, 0.5f, 0.5f, 0.5f); underwaterColor = new Color (0.22f, 0.65f, 0.77f, 0.5f); } // Update is called once per frame void Update () { if ((transform.position.y < waterHeight) != isUnderwater) { isUnderwater = transform.position.y < waterHeight; if (isUnderwater) SetUnderwater (); if (!isUnderwater) SetNormal (); } } void SetNormal () { RenderSettings.fogColor = normalColor; RenderSettings.fogDensity = 0.01f; } void SetUnderwater () { RenderSettings.fogColor = underwaterColor; RenderSettings.fogDensity = 0.1f; } } The script is taken from here. I attach the script to the camera and if the camera is below the position y set in the variable - nothing happens.
Try Debug.Log-ing transform.position.y alongside waterHeight and see if those values are what you think they are.
I have displayed the variables in UI, the boolean is changing to true. somthing is wrong with the colors settings.
Try the linear fog... I believe it works on a wider range of targets. It's what I use for mobile too.