Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
336 views1 page

Underwater

This script enables underwater effects by attaching to the main camera. It checks the camera's y position each frame and if below an underwater level value, applies fog, changes the fog color to blue, increases fog density, and removes the skybox to simulate being underwater. Otherwise, it restores the default scene fog settings.

Uploaded by

api-537257222
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
336 views1 page

Underwater

This script enables underwater effects by attaching to the main camera. It checks the camera's y position each frame and if below an underwater level value, applies fog, changes the fog color to blue, increases fog density, and removes the skybox to simulate being underwater. Otherwise, it restores the default scene fog settings.

Uploaded by

api-537257222
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

...ortfolio\WaterDome\WaterDome\Assets\Scripts\Underwater.

cs 1
1 using UnityEngine;
2 using System.Collections;
3
4 public class Underwater : MonoBehaviour
5 {
6
7 //This script enables underwater effects. Attach to main camera.
8
9 //Define variable
10 public int underwaterLevel = 250;
11
12 //The scene's default fog settings
13 private bool defaultFog;
14 private Color defaultFogColor;
15 private float defaultFogDensity;
16 private Material defaultSkybox;
17 private Material noSkybox;
18
19 void Start()
20 {
21 defaultFog = RenderSettings.fog;
22 defaultFogColor = RenderSettings.fogColor;
23 defaultFogDensity = RenderSettings.fogDensity;
24 defaultSkybox = RenderSettings.skybox;
25 }
26
27 void Update()
28 {
29 if (transform.position.y < underwaterLevel)
30 {
31 RenderSettings.fog = true;
32 RenderSettings.fogColor = new Color(0, 0.4f, 0.7f, 0.6f);
33 RenderSettings.fogDensity = 0.005f;
34 RenderSettings.skybox = noSkybox;
35 }
36 else
37 {
38 RenderSettings.fog = defaultFog;
39 RenderSettings.fogColor = defaultFogColor;
40 RenderSettings.fogDensity = defaultFogDensity;
41 RenderSettings.skybox = defaultSkybox;
42 }
43 }
44 }

You might also like