Friday, 22 March 2013

Green Fog for Underwater Script

using UnityEngine;
using System.Collections;

public class Underwater : MonoBehaviour {

 //This script enables underwater effects. Attach to main camera.

    //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.70f, 200, 0.15f, 70);
    }

    void Update () {
        if (transform.position.y < underwaterLevel)
        {
            RenderSettings.fog = true;
            RenderSettings.fogColor = new Color(0.70f, 200, 0.15f, 70);  < This is where we have changed the colour.

            RenderSettings.fogDensity = 0.2f;  < This is where we have changed the density
           
        }
        else
        {
            RenderSettings.fog = defaultFog;
            RenderSettings.fogColor = defaultFogColor;
            RenderSettings.fogDensity = defaultFogDensity;
          
        }
    }
}

No comments:

Post a Comment