Table of Contents
Accessing fog properties
All properties shown in the inspector can be set or modified at runtime using scripting.
First you need to get a reference to the main script which can be done easily using:
using VolumetricFogAndMist2; … VolumetricFog fog = volumeObject.GetComponent<VolumetricFog>;
(where volumeObject is the gameobject of the fog volume)
Then, you can change any profile property like the fog color or wind speed/direction:
fog.profile.albedo = new Color(1,0,0); fog.profile.windDirection = Vector3.right;
You can also access the properties using the “settings” accessor which will create an internal copy of the profile the first time you use it so any change to the properties will only affect that fog instance. Example:
fog.settings.albedo = new Color(1,0,0);
Creating fog volumes at runtime
Use this code to create a new fog volume using code:
GameObject fogVolume = VolumetricFogManager.CreateFogVolume(“New Fog Volume”);
Creating fog voids at runtime
Use this code to create a new fog void using code:
GameObject fogVoid = VolumetricFogManager.CreateFogVoid(“New Fog Void”);
Fog of War methods
The following fog of war methods are available:
Property that returns or set the fog of war texture.
General reset function which removes any previous change to fog of war transparency.
Restores fog immediately at a given position with radius or bounds.
Returns the opacity of the fog at a given world position.
Changes the transparency of the fog in an area. This method is overloaded and can accept different paremeters and options:
A world position and a radius, or a bounds object or a world position and size.
Desired alpha and specify if this value replaces the existing transparency or if it blends with it (blendAlpha parameter).
The duration of the transition (pass 0 to set the alpha immediately).
The smoothness/harshness of the border (by default it uses the global setting in Fog Of War section which is 1f).
The restore delay and duration (by default it uses the global settings in Fog Of War section). Pass 0 to restore delay to make the change permanent.