- Home /
Need some help with controlling audio with ui slider .
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Audio;
using TMPro;
public class GameStatus : MonoBehaviour
{
[SerializeField] public TextMeshProUGUI ScoreDisplay;
[SerializeField] public TextMeshProUGUI WaveDisplay;
[SerializeField] [Range(0, 1)] public float deathVolume;
[SerializeField] AudioClip playerFireSound; ///Fire Sound
[SerializeField] public Slider Soundslider; /// Slider to control the sound
public GameObject PauseMenuPanel;
public EnemySpawner enemySpawner;
public AudioMixer audioMixerMusic;
int score;
public static int highScore;
public static bool GameIsPaused = false;
void Start()
{
enemySpawner = FindObjectOfType<EnemySpawner>();
}
public void SetMusicLevel(float music)
{
audioMixerMusic.SetFloat("MusicVolume", music);
}
public void SetSoundLevel(float deathVolume)
{
Soundslider.value = deathVolume; // slider takes float value but the sound remains unchanged..HELP!!
}
void Update()
{
ScoreDisplay.text = GetScore().ToString();
highScore = int.Parse(ScoreDisplay.text);
PlayerPrefs.SetInt("NewScore", highScore);
WaveDisplay.text = enemySpawner.WaveCount.ToString();
if(Input.GetKeyDown(KeyCode.Escape))
{
if(GameIsPaused)
{
Resume();
}
else
{
Pause();
}
}
}
public void FireSound()
{
if (GameObject.Find("Player") != null)
{
AudioSource.PlayClipAtPoint(playerFireSound, Camera.main.transform.position, deathVolume);
}
}
I've commented out the part which i'm troubled with. Here this GameStatus script is referenced with slider OnValueChanged event where it takes the float value from deathSound . but when the slider is changed during play mode the value doesn't get updated. Whereas when i change it from the inspector in this script it does changes. What am i missing here, please can someone help me out with it..:)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612201044im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Controlling Master Volume with one slider? 1 Answer
How to add sound to the movement of the radial slider 0 Answers
Change sound dependent on slider? 1 Answer
Control animator with slider 0 Answers
Why hip will move upward and downward automatically when start to drag slider at x,y and z axis? 0 Answers