c# underwater effect help

Hello unity forum members,
First off i want to let you know im really new to c# so i might be going about this script the wrong way.

This is currently my script:

using UnityEngine;
using System.Collections;

public class Underwatersrc : MonoBehaviour {

public Transform Player;
	
	
	
	void OnGUI() {
		
		float fogon = Vector3.Distance(Player.position, transform.position);
	
		
		
		if(fogon <10){
		RenderSettings.fogMode = FogMode.Exponential;
		RenderSettings.fog = true;
			RenderSettings.fogDensity = 0.35f;
			RenderSettings.fogColor = new Color (0.22f, 0.65f, 0.77f, 0.5f);
			
		}
		
		else {
			
				RenderSettings.fogMode = FogMode.Linear;
		RenderSettings.fog = true;
			RenderSettings.fogDensity = 0.85f;
			RenderSettings.fogColor = Color.white;
			
		}
	}
	
}

As you can see when this script is attached to an object it will correctly change the fog type and colour. However, when this is attached to a massive plane, the distance number has to be really huge. I was hoping someone would be able to show me a way of tweaking this so that the fog changed color if the player moves below a certain point ie, under the water level (which is -1) in my game, so <0.

I tried to do transform.position.y, but that didn’t work, it had too many errors.

Many thanks in advance,

Ice

In a first person game, you should compare the camera Y coordinate to the water Y - this will tell when the character “eyes” (the camera) are above or below the water level. Another point: do it in Update, not in OnGUI:

public float waterLevel = -1; // adjust the water level in the Inspector

void Update(){ // use Update instead of OnGUI
  // compare the camera Y coordinate to the water level:
  if (Camera.main.transform.position.y < waterLevel){
    // set underwater fog
  } else {
    // set regular fog
  }
}