Search Unity

Question How do i start a music in an specific scene

Discussion in 'Scripting' started by RubenVanOostveen, Sep 28, 2020.

  1. RubenVanOostveen

    RubenVanOostveen

    Joined:
    Jul 31, 2020
    Posts:
    91
    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.
     
  2. Dextozz

    Dextozz

    Joined:
    Apr 8, 2018
    Posts:
    493
  3. RubenVanOostveen

    RubenVanOostveen

    Joined:
    Jul 31, 2020
    Posts:
    91
    It gave me an error: upload_2020-9-29_8-18-56.png
    How can I fix that?
     
  4. Dextozz

    Dextozz

    Joined:
    Apr 8, 2018
    Posts:
    493
    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.