Hi everyone,
I’m new on Unity programming, and I’m trying to have some Underwater effects but I’m facing a problem because I need to serialize my code but even with the documentation I don’t understand a thing!
My simple code is :
var underwaterLevel =80;
private var Fog = RenderSettings.fog;
private var FogColor = RenderSettings.fogColor;
private var FogDensity = RenderSettings.fogDensity;
function Start () {
}
function Update () {
if (transform.position.y < underwaterLevel){
RenderSettings.fog = true;
RenderSettings.fogColor = Color32(95, 160, 188, 128);
RenderSettings.fogDensity = 0.04;
}
}
and my error is :
UnityException: get_fog is not allowed to be called from a MonoBehaviour constructor (or instance field initializer), call it in Awake or Start instead. Called from MonoBehaviour ‘UnderWater’ on game object ‘Main Camera’.
See “Script Serialization” page in the Unity Manual for further details.
UnderWater…ctor () (at Assets/Scripts/UnderWater.js:5)
UnityEditorInternal.InternalEditorUtility:HierarchyWindowDrag(HierarchyProperty, Boolean, HierarchyDropMode)
UnityEditor.DockArea:OnGUI()
So if someone could help me it would be really cool!
Thanks