Thursday, 21 March 2013

Underwater Script

using UnityEngine;
using System.Collections;

public class Underwater : MonoBehaviour {

//This script enables underwater effects.     //Define variable
    public int underwaterLevel = 1064;

    //The scene's default fog settings
    private bool defaultFog = RenderSettings.fog;
    private Color defaultFogColor = RenderSettings.fogColor;
    private float defaultFogDensity = RenderSettings.fogDensity;
    private Material defaultSkybox = RenderSettings.skybox;

    void Start () {
    //Set the background color
    camera.backgroundColor = new Color(0, 0.4f, 0.7f, 1);
    }

    void Update () {
        if (transform.position.y < underwaterLevel)
        {
            RenderSettings.fog = true;
            RenderSettings.fogColor = new Color(0, 0.4f, 0.7f, 0.6f);
            RenderSettings.fogDensity = 0.04f;
          
        }
        else
        {
            RenderSettings.fog = defaultFog;
            RenderSettings.fogColor = defaultFogColor;
            RenderSettings.fogDensity = defaultFogDensity;
          
        }
    }
}


This is the script we have used for the underwater effect. We have added it to the main camera.

No comments:

Post a Comment