Don't reload the AudioSource when back to scene

Simple question but make me blur.

I have an audio source on let say “Main” scene, and I make it DontDestroyOnLoad, which make it could keep playing my audio even i going next scene, let say “Game” scene.

Problem is, when i get back from “Game” scene to “Main” scene, my audio will restart over but not continue playing as i expected. How should i actually script for this?

My current script :

void Awake() {
if (instance != null && instance != this) {
Destroy(this.gameObject);
return;
} else {
instance = this;
}
DontDestroyOnLoad(this.gameObject);
}

I guess the problem here is that when you load the scene again, this will never be the same as instance, because it’s technically speaking a different object. Also the object that’s kept loaded will not receive the Awake() call!

I would try it like this:

static Object instance = null;

void Awake()
{
	if (instance != null)
	{
		Destroy (this.gameObject);
		return;
	}
	else
	{
		instance = this;
		DontDestroyOnLoad (this.gameObject);
	}
}

void OnDestroy()
{
	if (instance == this)
	{
		instance = null;
	}
}