Created
July 5, 2016 15:36
-
-
Save chuckbergeron/0f6b1184f750dd8607c574247330428e to your computer and use it in GitHub Desktop.
Changing StandardAsset ImageEffects on Camera at runtime in Unity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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