- Home /
Destroy gameobject when THIS scene is loaded
Hi everybody, Im new on the forum so the problem : I have an AudioSource with DontDestroyOnLoad but i want this only on my menu and the music stay on the map scene.
So how can i Destroy the AudioSource when "Map01" is loaded ? Sorry if i made mistakes i'm french.
Comment
Best Answer
Answer by MajdHamada · May 02, 2015 at 08:25 PM
Use this Script...
function Start(){
if( Application.loadedLevelName=="YourScene"){
Destroy( YourGameObject );
}}
you Can also do it in function UpDate()
Ins$$anonymous$$d of adding this code to your Start function you could use this: void OnLevelWasLoaded(int level) { if (level == 13) // Replace this number for your level number { Destroy(gameObject); } }
Can You Accept the answer ....So that users benefit from it