Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Changing StandardAsset ImageEffects on Camera at runtime in Unity
using DG.Tweening; // remove this if you're not using DOTween
using System.Collections;
using UnityEngine;
using UnityStandardAssets.ImageEffects;
/// <summary>
/// An extension class for dynamically adding noise to the camera easily at runtime
/// </summary>
public class DynamicCameraEffects : MonoBehaviour
{
private static NoiseAndGrain _noiseScript;
private void Start()
{
_noiseScript = GetComponent<NoiseAndGrain>();
}
public static void BringTheNoise(float newIntensity, float duration)
{
DOTween.To(() => _noiseScript.intensityMultiplier, x => _noiseScript.intensityMultiplier = x, newIntensity, duration)
.SetEase(Ease.OutCirc)
.SetUpdate(true)
.OnComplete(RemoveNoise);
}
private static void RemoveNoise()
{
var duration = Random.Range(0.2f, 1f);
DOTween.To(() => _noiseScript.intensityMultiplier, x => _noiseScript.intensityMultiplier = x, 0.45f, duration)
.SetEase(Ease.InQuad)
.SetUpdate(true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment