Audio script (497364)

hello,

I made a 2d platformer with 4 level. now I want to make one song in level 1 and 2 and an other song in level 3 and 4.

I made a gameobject with audiosource in level 1 and attached this script (because I don’t want to start the song from the beginning when I am respawn)

private static var instance:MyUnitySingleton;
public static function GetInstance() : MyUnitySingleton {
return instance;
}

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

In level 3 I want to change the song what should I do?

Include a function to destroy the instance, and call it from another script when you load level 3. The fact that it doesn’t destroy on load doesn’t mean it can’t be destroyed manually.

Happy coding!

Why make two threads for the same problem? This is un-needed.

Posting duplicate topics is against the rules. Also use code tags when posting code.

–Eric