- Home /
createing a underwater java script ArgumentException: get_fog.
i am getiing two error the first one is
ArgumentException: get_fog can only be called from the main thread. Constructors and field initializers will be executed from the loading thread when loading a scene. Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function. underwater..ctor () (at Assets/Standard Assets/Water (Basic)/underwater.js:15)
the second one is
UnityEngine.RenderSettings:get_fog() underwater:.ctor() (at Assets\Standard Assets\Water (Basic)\underwater.js:15)
the script i have done so far is
function Update () { }//This script enables underwater effects. Attach to main camera.
//Define variables
var underwaterLevel = 102.8067;
// Enable fog RenderSettings.fog = true;
//The scene's default fog settings private var defaultFog; private var defaultFogColor : Color; private var defaultFogDensity : float; private var defaultSkybox : Material; var noSkybox : Material;
function Start () {
defaultFog = RenderSettings.fog;
defaultFogColor = RenderSettings.fogColor;
defaultFogDensity = RenderSettings.fogDensity;
defaultSkybox = RenderSettings.skybox;
//Set the background color camera.backgroundColor = Color (0, 0.4, 0.7, 1); }
if (transform.position.y < underwaterLevel) {
RenderSettings.fog = true;
RenderSettings.fogColor = Color (0, 0.4, 0.7, 0.6);
RenderSettings.fogDensity = 0.04;
RenderSettings.skybox = noSkybox;
}
else {
RenderSettings.fog = defaultFog;
RenderSettings.fogColor = defaultFogColor;
RenderSettings.fogDensity = defaultFogDensity;
RenderSettings.skybox = defaultSkybox;
}
ANY HELP TO GET RID OF THESE ERRORS WILL BE VERY APPRIECATED
THANKS VERY MUCH IF YOU NEED TO ASK ANY QUESTIONS JUST ASK AHEAD
Answer by aldonaletto · Nov 09, 2011 at 01:09 AM
You scrambled the code lines. The correct order should be:
//This script enables underwater effects. Attach to main camera.
//Define variables
var underwaterLevel = 102.8067;
//The scene's default fog settings private var defaultFog; private var defaultFogColor : Color; private var defaultFogDensity : float; private var defaultSkybox : Material; var noSkybox : Material;
function Start () { defaultFog = RenderSettings.fog; defaultFogColor = RenderSettings.fogColor; defaultFogDensity = RenderSettings.fogDensity; defaultSkybox = RenderSettings.skybox; //Set the background color camera.backgroundColor = Color (0, 0.4, 0.7, 1); }
function Update () { if (transform.position.y < underwaterLevel) { // Enable fog RenderSettings.fog = true; RenderSettings.fogColor = Color (0, 0.4, 0.7, 0.6); RenderSettings.fogDensity = 0.04; RenderSettings.skybox = noSkybox; } else { RenderSettings.fog = defaultFog; RenderSettings.fogColor = defaultFogColor; RenderSettings.fogDensity = defaultFogDensity; RenderSettings.skybox = defaultSkybox; } }
Your answer
![](https://koobas.hobune.stream/wayback/20220613035523im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
underwater fog script 1 Answer
need water 1 Answer
Underwater effect question 2 Answers
Underwater Effect 1 Answer
underwater shader 1 Answer