- Home /
How to carry over audiosource, only on certain levels.
I'd like to have my audio source carry over for each "castle" level, but if the player goes to a non "castle" level, i'd like for the audiosource to be destoryed. I'm not sure how to get the level names into the code though.
public class CastleMusicManager : MonoBehaviour {
void Start () {
DontDestroyOnLoad(gameObject);
}
// Update is called once per frame
void Update () {
if(Application.loadedLevelName != "Castle1" || "Castle2" || "Castle3")
{
Destroy(gameObject);
}
}
}
Something sort of along these lines.
Comment
Best Answer
Answer by Simon-Larsen · Jan 16, 2015 at 04:48 PM
The simple solution is sticking to the naming of the 'Castle' levels, that means your castle levels must contain the string "Castle" in their names.
if(!Application.loadedLevelName.Contains("Castle"))
{
Destroy(gameObject);
}
Your answer