- Home /
Question by
ItArth · Apr 12, 2020 at 03:30 PM ·
scripting problemaudiofade
Audio Fade With Toggle
I whant a toggle that when it's get off the audio Source volume get's faded to 0 and when the toggle get's on the volume of the source come again to 1 faded, how i can do that My script is wrong. This is my Script :
using UnityEngine;
public class PauseAudio : MonoBehaviour
{
public AudioSource _Source;
public float currentVolume;
public float fadeSpeed;
public bool On = true;
void Update()
{
currentVolume = _Source.volume;
Pause();
}
public void Pause ()
{
if (On)
{
currentVolume = Mathf.MoveTowards(currentVolume, 1, fadeSpeed * Time.deltaTime);
}
if (!On)
{
currentVolume = Mathf.MoveTowards(currentVolume, 0, fadeSpeed * Time.deltaTime);
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612231213im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
accessing the previous click object information 0 Answers
Glitched Music 0 Answers
Audio Clip Playing every frame 2 Answers
Fade audio in and out for Jet Engine 1 Answer
audio doesn't play on movement 0 Answers