slider UI event/functions

Here's a way to get sliders to control VFX graph values

 

using UnityEngine;
using System.Collections;
using UnityEngine.UI; // Required when Using UI elements.
using UnityEngine.VFX;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;




public class slider_ctrl : MonoBehaviour
{
    public Slider _mainSlider;
    public VisualEffect _visualEffect;
    public Volume _volume;
    [SerializeField]
    private float _whateverValue = 0;

    public void Start()
    {
        //Adds a listener to the main slider and invokes a method when the value changes.
        _mainSlider.onValueChanged.AddListener(delegate { ValueChangeCheck(); });
    }

    // Invoked when the value of the slider changes.
    public void ValueChangeCheck()
    {
        _visualEffect.SetFloat("ball_rate", _mainSlider.value * 5);

//ball_rate is the exposed float variable we've created in a hypothetical VFX graph
    
    }
}

Comments

Popular posts from this blog

Unity's "new" input system and Keijiro's Minis midi stuff

setting VFX graph properties using C#