- Home /
Is there a tutorial for creating the underwater effect from scratch?
Is there a tutorial for creating an underwater effect from scratch? I'm having troubles recreating the underwater features from the island demo.
Thanks.
Answer by josif · Jun 01, 2010 at 11:19 PM
try this its inset the best on but it will have to do you need to put it on the main cam and you need to call it underwater its also a JavaScript good luck
//This script enables underwater effects. Attach to main camera.
//Define variables var underwaterLevel = 7;
//The scene's default fog settings private var defaultFog = RenderSettings.fog; private var defaultFogColor = RenderSettings.fogColor; private var defaultFogDensity = RenderSettings.fogDensity; private var defaultSkybox = RenderSettings.skybox; var noSkybox : Material;
function Start () { //Set the background color camera.backgroundColor = Color (0, 0.4, 0.7, 1); }
function Update () { 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;
}
}
I tried this script and it seems to work, but Unity is giving me errors. I'm using 3.5.
The error I get 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.
If this is a version difference, do you have a similar script that works with 3.5?
@Phoebert I think that error is when you can't read some data outside of a function, most likely becuase the data hasn't loaded yet. Try putting
private var defaultFog;
at the beggining and putting
defaultFog = RenderSettings.fog;
at the beggining of the Start function. Do the same thing for each of the 4 private vars...
private var defaultFog;
private var defaultFogColor;
private var defaultFogDensity;
private var defaultSkybox;
var noSkybox : $$anonymous$$aterial;
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);
}
Scribe
I tried it and I was wondering if you could go into more detail on the error correction? And one more thing, is it possible to add a skybox at all? I tried adding it to the script, that didn't work, (hence the var noskybox) so I tried attaching it separately. Which didn't work either.
Thanks Scribe that complexly fixed it. Struggling to get the water level at the correct hight though. $$anonymous$$aybe it needs to be a Float or something, am trying to figure it out. Thanks for the fix!
Answer by mukul18khanna · Dec 26, 2017 at 11:36 AM
This might help-
https://medium.com/@mukulkhanna/creating-basic-underwater-effects-in-unity-9a9400bde928
Your answer

Follow this Question
Related Questions
Visual Effect Graph: How to expose parameter to flexibly set Capacity from Inspector? 0 Answers
Visual Effects Graph and Custom Renderer not working together 0 Answers
Want Main Camera to show what fxcamera is rendering 0 Answers
How to render part of an object 2 Answers
Messy normals with Transparent material 0 Answers