The GameObject “Jukebox” exists in another scene, and has “DoNotDestroy” attached, but the following script returns “No object found with that name!”:
var juke = GameObject.Find("Jukebox"); // search
if (juke == null) {print("No object found with that name!");} // check if object was found
else {print("someObject name: " + juke.name); // if found, print name
I made sure of correct spelling of “Jukebox”, no extra spaces, only “J” capitalized.
GameObject.Find does not work across scenes - if you don’t have an instance of JukeBox in the currently loaded scene, it will return null.
I’ve tested this, and it worked fine. I attached this code to the jukebox script:
function Awake(){
DontDestroyOnLoad(transform.gameObject);
}
I tested the startup scene in the Editor, then changed to the new scene by script (using Application.LoadLevel) and the Jukebox was there (despite the music stopped!).
But this only works if you are coming from the startup scene! If you try to test the other scenes in the Editor you will get an error, because the Jukebox has never been created.