- Home /
,Help with this code for AudioSource Please.
using UnityEngine; using UnityEngine.UI;
public class AudioManagerTutorial : MonoBehaviour { private static readonly string FirstPlay = "FirstPlay"; private static readonly string BackgroundPref = "BackgroundPref"; private int firstPlayInt; public Slider backgroundSlider; private float backgroundFloat; public AudioSource backgroundAudio;
void Start()
{
firstPlayInt = PlayerPrefs.GetInt(FirstPlay);
if (firstPlayInt == 0)
{
backgroundFloat = .125f;
backgroundSlider.value = backgroundFloat;
PlayerPrefs.SetFloat(BackgroundPref, backgroundFloat);
PlayerPrefs.SetInt(FirstPlay, -1);
}
else
{
backgroundFloat = PlayerPrefs.GetFloat(BackgroundPref);
backgroundSlider.value = backgroundFloat;
}
}
public void SaveSoundSettings()
{
PlayerPrefs.SetFloat(BackgroundPref, backgroundSlider.value);
}
void OnApplicationFocus(bool inFocus)
{
if (!inFocus)
{
SaveSoundSettings();
}
}
public void UpdateSound()
{
backgroundAudio.volume = backgroundSlider.value;
}
void Awake ()
{
DontDestroyOnLoad(this.gameObject);
}
public void Stop()
{
backgroundAudio.Stop();
}
} Help with the last function. I need to end this audio clip when the second one is played. Help please my due date is coming up:(,using UnityEngine; using UnityEngine.UI;
public class AudioManagerTutorial : MonoBehaviour { private static readonly string FirstPlay = "FirstPlay"; private static readonly string BackgroundPref = "BackgroundPref"; private int firstPlayInt; public Slider backgroundSlider; private float backgroundFloat; public AudioSource backgroundAudio;
void Start()
{
firstPlayInt = PlayerPrefs.GetInt(FirstPlay);
if (firstPlayInt == 0)
{
backgroundFloat = .125f;
backgroundSlider.value = backgroundFloat;
PlayerPrefs.SetFloat(BackgroundPref, backgroundFloat);
PlayerPrefs.SetInt(FirstPlay, -1);
}
else
{
backgroundFloat = PlayerPrefs.GetFloat(BackgroundPref);
backgroundSlider.value = backgroundFloat;
}
}
public void SaveSoundSettings()
{
PlayerPrefs.SetFloat(BackgroundPref, backgroundSlider.value);
}
void OnApplicationFocus(bool inFocus)
{
if (!inFocus)
{
SaveSoundSettings();
}
}
public void UpdateSound()
{
backgroundAudio.volume = backgroundSlider.value;
}
void Awake ()
{
DontDestroyOnLoad(this.gameObject);
}
public void Stop()
{
backgroundAudio.Stop();
}
}
My main problem is public void Stop() { backgroundAudio.Stop(); } I want to make this audioclip end when the next one is played. Please help my due date is coming up(
Your answer

Follow this Question
Related Questions
Stop moving rigidbody but don't stop rotating 1 Answer
Enemy rams my player? 1 Answer
How to stop the enemy from jumping when chasing the player ? 1 Answer
how to stop animation loop? 1 Answer
Stop rotation if a key is pressed 2 Answers