Help me with this code. It's so simple. You can

Hi, everyone. Please teach me and fix the error.

In my Unity project, I have a camera and I want to control the brightness of Camera view. when I am falling down from a high place, I want to see the white splash within my camera view so that there is nothing to see.

My code is:

public class ScreenBrightnessController : MonoBehaviour
{
    public float maxBrightness = 1.0f;
    public float fallSpeed = 10.0f;
    private float currentBrightness = 0.0f;
    private void Update()
    {
            currentBrightness += Time.deltaTime * fallSpeed;
            currentBrightness = Mathf.Clamp01(currentBrightness);
            Screen.brightness = currentBrightness;
or (Screen.SetBrightness(brightnessValue);)
    }
}

It doesn’t work anything. The brightness is not changing.

The error is:

‘Screen’ does not contain a definition for ‘SetBrightness’

And my version is - 2022.3.13f1.

please help me.
I want to make it like this video. Richel’s plank experience falling screen.
Thank you and I am waiting for your voice.

Try:

Screen.SetBrightness(brightnessValue);

instead of:

or (Screen.SetBrightness(brightnessValue);)

I did it, too. But there was a error that it can’t find “SetBrightness()” function in “Screen”.

You need to use post processing!

This tutorial should help you:

Just dont apply the logic of the slider.

And it doesnt work for urp or hdrp afaic

Thank you, but Could you guide me in more detail, on meeting, please? I am not clear in post processing.

This is the script for URP:

using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;

public class Test : MonoBehaviour
{

    [Header("Post Processing")]
    public VolumeProfile volumeProfile;
    private float bloomIntensity;
    private Bloom bloom;

    [Header("Falling")]
    public float maxBrightness = 500f;
    public float minBrightness = 1.0f;
    public float changeSpeed = 100.0f;
    [SerializeField] private bool falling; // this doesnt need to be serialized because you will probably end up setting the bool in your script. This was for testing.


    private void Start()
    {
        volumeProfile.TryGet(out bloom);
    }

    private void Update()
    {
        if (falling)
            BrightenScreen();

        else if (!falling)
            DarkenScreen();

    }

    private void BrightenScreen()
    {
        if (bloom.intensity.value >= maxBrightness)
            return;

        bloomIntensity += Time.deltaTime * changeSpeed;

        bloom.intensity.value = bloomIntensity;
    }

    private void DarkenScreen()
    {
        if (bloom.intensity.value <= minBrightness)
            return;

        bloomIntensity -= Time.deltaTime * changeSpeed;

        bloom.intensity.value = bloomIntensity;
    }

}

The only “problem” here, is that if you change postprocessing effects in playMode, it stays like it even if you close it. So you might have to set the post processing bloom intensity to 1 in your inspector manually sometimes.