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