- Home /
AudioSource.Pause not working?
my game pauses fine , but audioSource is not pausing why ? and in audiosource , playOnAwake is false.
public bool isPaused;
public GameObject pauseMenuCanvas;
public AudioSource AC;
public GameObject TouchToPlay;
void Start () {
pauseMenuCanvas.SetActive (false);
TouchToPlay.SetActive (true);
Time.timeScale = 0f;
}
void Update () {
if (isPaused) {
AC.Pause ();
pauseMenuCanvas.SetActive (true);
Time.timeScale = 0f;
} else if(!isPaused){
pauseMenuCanvas.SetActive (false);
AC.UnPause ();
Time.timeScale = 1f;
}
if (Input.GetKeyDown (KeyCode.P)) {
isPaused = !isPaused;
}
}
public void TouchPlay(){
TouchToPlay.SetActive (false);
Time.timeScale = 1f;
AC.Play ();
}
Did you solve this issue? I seem to have the same problem.
Answer by Ali-hatem · Mar 14, 2017 at 12:58 PM
bool is_Paused;
public AudioSource asource;
void Update () {
if (Input.GetKeyDown (KeyCode.P)) {
if (!is_Paused) {
asource.Pause ();
is_Paused = true;
} else {
asource.UnPause ();
is_Paused = false;
}
}
}
@EagleDanger you have to be careful about codes in update
I actually just had placed the prefab and not the object in question to the script, so it was an easy fix when I found my error. Thanks anyway!
Answer by justinyeh · Oct 21, 2016 at 02:53 PM
If the timeScale
= 0f
i think the script won't update.
my game pauses and resumes fine , that means update starts fine but AC.pause doesn't work
Ah! The timeScale = 0
just make FixedUpdate pause
i changed Update into FixedUpdate , and that doesn't work
Your answer
Follow this Question
Related Questions
Audio Issue 1 Answer
How would I go about using music from StreamingAssets folder (imported by the player) 0 Answers
Unity Unable to Reassign Audio Clip 1 Answer
How to make music play always without duplicates? 0 Answers
Music On/Off Switch 2 Answers