How do i start a music in an specific scene

So I want to loop a piece of music when I’m in scene Menu. I have created a simple audio file from 5 seconds I wanna repeat. but when I load up a new scene the music has to stop (In order to play fitting music instead of the same 5 seconds over and over) But I don’t know how to do that. I tried changing range and stuff but it needs to go through scripts. I just don’t know the right callouts. Neither do I need a fully made script? {but something like a link if existed) Or wich callouts I would need! then I would be very happy.

Use an event that fires when you enter a scene:

Then, simply play the music you want based on the scene loaded. For example

if(scene.name.CompareTo("YourSceneNameHere") == 0)
{
   // Play music
}

It gave me an error:


How can I fix that?

Did you see the link I mentioned? Don’t use Update(). Use OnEnable to subscribe to an event, OnDisable to unsubscribe. Take another look at the link I mentioned and try figuring it out.

The exact reason for getting that error is because the variable scene is not defined anywhere. Once you follow the link, you’ll be able to get it from SceneManager.onSceneLoaded.