- Home /
How to destroy a script on loadlevel?
Hi, I have 3 scenes, the first two have the same music, and the the third scene is the game, but in the game scene there should not be the music that there is in the first two scenes. The music is off only if I remove the audiolistener. But I need it in the game Scene.. So, How can I do to destroy that script that contains the music for the first and second level?
Answer by Soos621 · Nov 11, 2015 at 07:18 PM
You should have audio sources for the music and enable or disable them according to the scene. http://docs.unity3d.com/ScriptReference/AudioSource.html
In the game scene there isn't the audiosource of the first and second scene. This script works attacking a gameobject named '$$anonymous$$USIC' to the scene that you want the music, but in the game scene there is not a gameobject named '$$anonymous$$USIC', but it appears when the level is loaded. How can I do to destroy this script in this specific scene?
$$anonymous$$aybe I have to destroy the gameobject '$$anonymous$$usic'?
if you really want to do it that way (which I'm sure there are better options) you can check which scene you are currently in with application.loadedlevel or application.loadedlevelname and if that scene corresponds with the scene you want to destroy the objct in, then destroy that object
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
NullReferenceException - When destroying Object 1 Answer
Multiple gameobjects but only one is screen wrapping. 0 Answers