(Unity)SliderでPintLightとBloom(ポストプロセス)のIntensityを変化させる(スクリプトでIntensityを動的に変化させる)

(スクリプト)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// ★追加
using UnityEngine.Rendering.PostProcessing;
using UnityEngine.UI;

public class LightManager : MonoBehaviour
{
    public PostProcessVolume ppVolume;
    public Light pointLight;
    public Slider lightSlider;
    private Bloom bloom;

    void Start()
    {
        bloom = ppVolume.profile.GetSetting<Bloom>();

        lightSlider.onValueChanged.AddListener(ChangeValue);
    }

    void ChangeValue(float intensity)
    {
        bloom.intensity.value = intensity;

        pointLight.intensity = intensity;
    }
}

(設定)

・Create Emptyを作成→名前を「LightManager」に変更

・これにスクリプトを追加

・空欄を追加

・スライダーの最大値を設定


(実行)