Modify Post-Processing Effects Through Code in Unity
Bringing dynamic effects to the game
Objective: Add and effect when the player pick the speed boost powerup
If you don’t have the post processing game object in your scene I am gonna leave you an article explaining how to create it.
We are gonna add the effect called Chromatic Aberration, this effect creates a distortion that can be used to simulate a super speed in the spaceship. We have to modify the value of the intensity to achieve that look.
Now we have to create a PostProcessing script, use the namespace UnityEngine.Rendering.PostProcessing and declare 2 variables. One to get the reference to the post processing game object and other to get the effect.
Then in the Start method we are gonna get the effect using the function PostProcessVolume.profile.TryGetSettings() and pass the _speedEffect variable as a parameter.
We have to create a public function to modify the intensity value of the _speedEffect variable.
In the player script we have to create a variable and assign the reference to the post processing object. Finally in the coroutine SpeedBoostCooldown we have to call the function to modify the speed effect.
And that’s all! You have a functional code to change post processing effects during the game.
For more information I leave you this link to the post processing documentation: