- Home /
Turning Post-Processing on/off with a key.
This should be super simple, but I can't get it to work. The player is instantiated so I can't move FindWithTag to Start(), I'll work something better out later, I just need to get it to work first.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.PostProcessing;
public class DevShortcuts : MonoBehaviour {
[Header("Feature Toggle Shortcuts")]
public KeyCode togglePostProcessing = KeyCode.F1;
public PostProcessingBehaviour player;
void Update ()
{
if( Input.GetKeyDown(togglePostProcessing))
{
player = GameObject.FindWithTag("Player").gameObject.GetComponentInChildren<PostProcessingBehaviour>();
print ("Post Off!");
print(player.enabled);
player.enabled = !player.enabled;
}
}
}
I can even put print(player.enabled) inside the If statement and it tells me it's enabled, so I don't see why it isn't changing...
Thanks to anyone who can point out my mistake :)
The 'enabled' property will only enable/disable the update of the behaviour. If you have changed something permanently through that script, it will not change.
Are you sure that you are only applying effects in the Update() method? If so, there could be something wrong with the PostProcessing script. If you could insert it here, we could take a look.
It's the PostProcessingBehaviour script from Unity's post-processing stack, it can be found on GitHub here: https://github.com/Unity-Technologies/PostProcessing