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);
}
}
}