- Home /
How to unpause an audiosource after pausing it in a previous scene?
So, I am working on this game for around 3 weeks already. This will be my first ever game and that means that the game itself is quite simple.
The only problem that I have is with my audio:
I use two kinds of audio. One for the menu and one for playing the game (levels).
For the audio playing when playing the game I`ve made a script that makes it so that the audio carries on even when the scene is destroyed (aka when the player respawns). That means that this audio just keeps playing even if I change the scene.
I`ve also made a button that transitions from current level to main menu. Because I have two different songs for menu and levels I want to pause the level audio via button and continue when starting another level.
How do I do this? I`ve tried several different things like googling, using the Pause and UnPause function via script but I can`t figure it out. Please help me.
Thanks in advance!
For the audio playing when playing the game I`ve made a script that makes it so that the audio carries on even when the scene is destroyed (aka when the player respawns). That means that this audio just keeps playing even if I change the scene.
If possible, please show your script. Did you use PlayOneShot?
using UnityEngine;
using System.Collections;
public class GameMusicPlayer : MonoBehaviour
{
private static GameMusicPlayer instance = null;
public static GameMusicPlayer Instance
{
get { return instance; }
}
void Awake()
{
if (instance != null && instance != this)
{
Destroy(this.gameObject);
return;
}
else
{
instance = this;
}
DontDestroyOnLoad(this.gameObject);
}
}
Your answer
Follow this Question
Related Questions
Pause, Unpause 1 Answer
Problem changing TimeScale 1 Answer
When i press play it just pauses right after. 6 Answers
How do i have a pause after i resume game C# 6.4 0 Answers
Pause Button Script 4 Answers