android - How to fade out audio/music between scenes? -
i'm trying music fade out when start android game. music plays in main menu , should fade out when player clicks play. can music stop, not fade out.
im trying fade out using this:
using unityengine; using system.collections; public class musicscript : monobehaviour { static musicscript instance; bool donefading; void start() { if(instance == null) { instance = this; dontdestroyonload(gameobject); } else if (instance != this) { destroy(gameobject); } } void update() { if (application.loadedlevelname == "flappy drone gameplay screen") { fademusic(); if (donefading == true) { destroy(gameobject); } } } ienumerator fademusic() { (int = 9; > 0; i--) { debug.log("here"); instance.audio.volume = * 0.1f; yield return new waitforseconds(0.5f); debug.log("lowered volume"); } donefading = true; } }
any appreciated!
after bit of playing time.deltatime found simple way of doing fade :)
code in same problem (this code fades out music on particular scene keeps music playing other scenes):
using unityengine; using system.collections; public class musicscript : monobehaviour { static musicscript instance; bool donefading; float timer = 5f; void start() { if(instance == null) { instance = this; dontdestroyonload(gameobject); } else if (instance != this) { destroy(gameobject); } } void update() { if (application.loadedlevelname == "flappy drone gameplay screen") { fademusic(); if (donefading == true) { destroy(gameobject); debug.log ("music destroyed."); } } } void fademusic() { if (timer > 0) { instance.audio.volume -= 0.015f; timer -= time.deltatime; } if (instance.audio.volume == 0) { donefading = true; } } }
Comments
Post a Comment