Search Unity

Animate fog color smoothly

Discussion in 'Scripting' started by ccburton, Sep 17, 2014.

  1. ccburton

    ccburton

    Joined:
    Mar 17, 2013
    Posts:
    31
    Hello, I would like to animate the Render Settings fog color, ideally smoothly over a period of 5 seconds. I'd like it to happen automatically when I enter Play mode. I'm very new to scripting, so I'd appreciate any help directed at my beginner level. Also, I understand that you can attach scripts to objects in the scene, but I don't know where you would attach a script that was affecting the Render Settings.

    PS I did find this http://forum.unity3d.com/threads/animate-fog-color.111353/ but all of the links point to a dead unifycommunity website.

    Thanks in advance and apologies for my beginner-ness.
     
  2. Zaladur

    Zaladur

    Joined:
    Oct 20, 2012
    Posts:
    392
    The concepts you will need for this are:

    Color.Lerp
    http://docs.unity3d.com/ScriptReference/Color.Lerp.html

    This will allow you to adjust color over time. The example used transitions over one second - multiplying the time factor by 0.2f will make the transition occur over 5 seconds.

    RenderSettings.fogColor
    http://docs.unity3d.com/ScriptReference/RenderSettings-fogColor.html

    This lets you change the fog color in your scripts. Combining this with Color.Lerp will tranistion FogColor over time.

    Finally, where do you actually put this code, since you don't see an object that directly correlates with RenderSettings?
    You can always create an Empty Gameobject to attach scripts such as this one too. Any object can access scene wide settings such as RenderSettings.
     
    wyao0819 likes this.
  3. ccburton

    ccburton

    Joined:
    Mar 17, 2013
    Posts:
    31
    Thank you for the reply! I will experiment with these references.