Search Unity

Question How to target a scene? and play audio only in that scene?

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

  1. RubenVanOostveen

    RubenVanOostveen

    Joined:
    Jul 31, 2020
    Posts:
    91
    So I made a scene for a basic menu. (Screenshot 1) That one is just called the menu. This scene plays a few high hats nothing special. But for the game itself (ScreenShot of level001) I wanna have a loop of a song I have found. The only problem is when I wanna play it it plays also on the menu. combining the music into eachother making the most terrible noise
    (Scrrenshot 1)
    (Here its meshing the 2 sounds)
    upload_2020-9-28_23-18-36.png
    Screen shot 2:
    (Here is the game where the music should be playing)
    upload_2020-9-28_23-19-17.png

    How do I do that. Something like GetScene or something
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,697
    Usually if you put the music in the scene and then load the next scene, the previous scene goes away, including audio, etc.

    You must be persisting the music in some fashion. Perhaps stop doing so? Or explicitly destroy whatever you originally persisted, if there's a reason to persist it?
     
  3. RubenVanOostveen

    RubenVanOostveen

    Joined:
    Jul 31, 2020
    Posts:
    91
    Actually, it is before the scene. I have the menu open and it starts to play. but I need it to play when I open level001
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,697
    So stop it before going back to Menu! :)
     
  5. RubenVanOostveen

    RubenVanOostveen

    Joined:
    Jul 31, 2020
    Posts:
    91

    Thats what is happening. it starts when the game starts.