x


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.

more ▼

asked May 31 '10 at 05:55 AM

mlkielb gravatar image

mlkielb
43 2 2 5

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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;
    }
}
more ▼

answered Jun 01 '10 at 11:19 PM

josif gravatar image

josif
212 19 22 35

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?

Jun 06 '12 at 05:58 PM Phoebert

@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 : 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);

}

Scribe

Jun 06 '12 at 06:17 PM Scribe

Thanks Scribe :) That fixed it!

Jun 07 '12 at 01:06 AM Phoebert

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.

Sep 24 '12 at 04:52 AM All.Else
(comments are locked)
10|3000 characters needed characters left

What is the script that will give me no errors? Please?

more ▼

answered Sep 21 '12 at 07:17 PM

CB-TV gravatar image

CB-TV
0 1

Hi There.

Please don't post comments as answers. Post comments by clicking the [add new comment] button, a window then open for you to type in. Answer fields are for answers only, as this is a knowledge base.

You can convert this answer to a comment (or just edit your original question), you'll also get a better chance of getting an actual answer if the main list shows none or one answer in blue =]

Sep 21 '12 at 08:29 PM alucardj
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x332
x47
x20

asked: May 31 '10 at 05:55 AM

Seen: 5628 times

Last Updated: Oct 01 '12 at 02:35 PM