unity3d - Cannot mute audiosource after returing to the scene (Unity C#) -
hello have menu scene have mute button , empty gameobject audiosource , dontdestroyonload script attached it. here code gameobject.
using unityengine; using system.collections; using unityengine.ui; public class backgorund_music_manger : monobehaviour { audiosource ads; public gameobject backgroundmusic; bool play_sound = true; void awake() { ads = getcomponent<audiosource>(); if(scenemanager.music == true) { destroy(this.gameobject); } else { dontdestroyonload(this.gameobject); } scenemanager.music = true; } void update() { if(scenemanager.currentscene == 4) { ads.volume = 0.1f; } else { ads.volume = 1f; } } public void stop_sound() { ads = getcomponent<audiosource>(); if(play_sound == true) { ads.pause(); play_sound = false; } else { ads.play(); play_sound = true; } } }
after going menu mute button stops working.
help
Comments
Post a Comment