How to set a button to change slider to specific value
I have a slider that controls an echo/delay time as wired to the audio mixer's effects (via exposed parameters - the parameter is called "delayTime." This is a musical app and so there is a tempo (BPM) and I have created buttons that automatically set to Tempo-Based Delays of 1/4 note, 1/8 note, and so forth.
What I need is for this button to also change the slider to be at that value. For instance, if by pressing the 1/4 Note delay button, the delay time changes to 600 ms, the Delay Time Slider should adjust accordingly. In my current setup, it does not.
In order to access the Audio Mixer ("masterMixer") I've tried using something called the masterMixer.GetFloat function, but not sure how to use it. Does anyone with Unity audio experience or relevant UI knowledge know how I could change this script?
Thank you!!
using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.Audio;
public class MixLevels: MonoBehaviour {
public AudioMixer masterMixer;
public radarScript _radarScript;
public Slider DelayTimeSlider;
// Tempo-Based Delay Values:
public float QuarterNoteDelayTime;
public float DottedEighthNoteDelayTime;
public float EighthNoteDelayTime;
public float DottedQuarterNoteDelayTime;
public float DelayTime;
void Update()
{
QuarterNoteDelayTime = (60000 / _radarScript.BPM);
DottedEighthNoteDelayTime = (45000 / _radarScript.BPM);
EighthNoteDelayTime = (30000 / _radarScript.BPM);
DottedQuarterNoteDelayTime = (90000 / _radarScript.BPM);
}
// TEMPO DELAY EQUATION:
// Quarter Note Delay Time = (60000 / BPM);
// where 60,000 = milliseconds per minute
// FOR TEMPO-BASED DELAY BUTTONS
public void SetQuarterNoteDelayTime ()
{
masterMixer.SetFloat ("delayTime", QuarterNoteDelayTime);
print ("button pressed; QuarterNoteDelayTime = " + QuarterNoteDelayTime);
}
public void SetDottedEighthNoteDelayTime ()
{
masterMixer.SetFloat ("delayTime", DottedEighthNoteDelayTime);
print ("button pressed; DottedEighthNoteDelayTime = " + DottedEighthNoteDelayTime);
}
public void SetEighthNoteDelayTime ()
{
masterMixer.SetFloat ("delayTime", EighthNoteDelayTime);
print ("button pressed; EighthNoteDelayTime= " + EighthNoteDelayTime);
}
public void SetDottedQuarterNoteDelayTime ()
{
masterMixer.SetFloat ("delayTime", DottedQuarterNoteDelayTime);
print ("button pressed; DottedQuarterNoteDelayTime = " + DottedQuarterNoteDelayTime);
}
// FOR MIXER FX PANEL WIRING
public void SetPitchLvl (float pitchLvl)
{
masterMixer.SetFloat ("pitchMaster", pitchLvl);
}
public void SetReverbDecayLvl (float reverbDecayLvl)
{
masterMixer.SetFloat ("reverbDecaytime", reverbDecayLvl);
}
public void SetReverbLvl (float reverbLvl)
{
masterMixer.SetFloat ("reverbMaster", reverbLvl);
}
public void SetFreqCutLvl (float freqCutLvl)
{
masterMixer.SetFloat ("filterCutoff", freqCutLvl);
}
public void SetMasterVolumeLvl (float masterVolumeLvl)
{
masterMixer.SetFloat ("MasterVolume", masterVolumeLvl);
}
public void SetChorusLvl (float chorusLvl)
{
masterMixer.SetFloat ("chorusDepth", chorusLvl);
}
public void SetDistortionLvl (float distortionLvl)
{
masterMixer.SetFloat ("distortionLevel", distortionLvl);
}
public void SetReverbDensityLvl (float reverbDensityLvl)
{
masterMixer.SetFloat ("reverbDensity", reverbDensityLvl);
}
public void SetDelaySendLvl (float delaySendLvl)
{
masterMixer.SetFloat ("delaySend", delaySendLvl);
}
public void SetDelayTimeLvl (float delayTime)
{
masterMixer.SetFloat ("delayTime", delayTime);
}
public void SetDelayFeedbackLvl (float delayFeedback)
{
masterMixer.SetFloat ("delayFdbk", delayFeedback);
}
}
Your answer
Follow this Question
Related Questions
How Do I Make A Change A Volume With A Slider? 3 Answers
Adjusting Audio Volume via UI Slider 0 Answers
UI not working properly in webgl build (new input system) 0 Answers
Drag UI Slider in VR with Vive Controllers 1 Answer
Slider OnValueChanged not letting me chose a function to send it to 1 Answer