Research & Development for 3D & the Web

Menu Music/Game Objects passing between scenes

by on May.20, 2010, under Unity Scripts

This is a very useful script to use when you want to be able to choose when / how to pass a game object onto another scene and then be able to return to a previous scene without ending up with duplicate objects.

(The script was taken from Unity Answers area on their site at the address below:)

http://answers.unity3d.com/questions/3863/audio-or-music-to-continue-playing-between-scene-changes

 

private static var instance:MusicHandler;

public static function GetInstance() : MusicHandler
{
return instance;
}

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

DontDestroyOnLoad(this.gameObject);
}

 

:programming, scripts, Unity

Leave a Reply

You must be logged in to post a comment.

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Blogroll

A few highly recommended websites...

Log In