Changing Values through code
You can just access the Dynamic Fog component and change the values
public class TestFog : MonoBehaviour
{
DynamicFog thisFog;
private void Start()
{
thisFog = FindObjectOfType<DynamicFog>();
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.J))
{
thisFog.distanceFallOff += 0.1f;
}
}
}
Changing Post Processing profile values from code
If you’re using the Post Processing Stack v2 version of the asset (see “How to Use this Asset” section), you can use this code to change the values of the profile at runtime.
using UnityEngine;
using DynamicFogAndMist;
using UnityEngine.Rendering.PostProcessing;
namespace DynamicFogAndMistDemos {
public class DynamicFogDistanceColor : MonoBehaviour {
DynamicFogPPS _fogSettings;
PostProcessVolume _volume;
/// <summary>
/// Returns a reference to the Post Processing Volume which contains Dynamic Fog effect.
/// </summary>
/// <value>The volume.</value>
public PostProcessVolume volume {
get {
if (_volume == null) {
_volume = FindObjectOfType<PostProcessVolume>();
}
return _volume;
}
}
/// <summary>
/// Returns a reference to the settings of Dynamic Fog & Mist in the Post Processing Profile
/// </summary>
/// <value>The shared settings.</value>
public DynamicFogPPS fogSettings {
get {
if (_fogSettings != null) return _fogSettings;
PostProcessVolume v = volume;
if (v == null) return null;
bool foundEffectSettings = v.sharedProfile.TryGetSettings<DynamicFogPPS>(out _fogSettings);
if (!foundEffectSettings) {
Debug.Log("Cant load Dynamic Fog settings");
return null;
}
return _fogSettings;
}
}
// Update is called once per frame to transition the color from white to blue in a loop
void Update() {
float t = Mathf.PingPong(Time.time * 0.1f, 1f);
fogSettings.color.value = Color.Lerp(Color.white, Color.blue, t);
fogSettings.color.overrideState = true;
}
}
}