Created
August 7, 2013 21:55
-
-
Save tatmos/6179144 to your computer and use it in GitHub Desktop.
Unity x ADX2LE 【効能】BGMがシーン切り替え時に自動停止します。
【使い方】BGM等の長めの音にAtomSource付きオブジェクトにコンポーネントとして貼付ける。
【使いどころ】シーン切り替え時のサウンド演出
エンベロープを長めにするとフェードアウトする演出になり、再生音が止まると自動消滅する。
シーンのつなぎ目で音がブチブチ切れないのでちょっと良い感じになります。
【補足】シーンをまたぐ場合、CriWareLibraryInitializerとCRIWAREはDont Destroy On Loadをチェックしておきます。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class IfSceneChangeDestroy : MonoBehaviour { | |
CriAtomSource atomSource = null; | |
// Use this for initialization | |
void Start () { | |
// error | |
if(GameObject.Find("CRIWARE") == null){ | |
Debug.LogWarning("CRIWARE is Null!"); | |
return; | |
} | |
atomSource = gameObject.GetComponent<CriAtomSource>(); | |
GameObject.DontDestroyOnLoad(this.gameObject); | |
} | |
// Update is called once per frame | |
void Update () { | |
if(stopUseFlag){ | |
if(atomSource.status == CriAtomSource.Status.PlayEnd | |
|| atomSource.status == CriAtomSource.Status.Stop | |
){ | |
GameObject.Destroy(this.gameObject); | |
} | |
} | |
} | |
bool stopUseFlag = false; | |
void OnLevelWasLoaded() | |
{ | |
if(atomSource.status != CriAtomSource.Status.PlayEnd){ | |
atomSource.Stop(); | |
stopUseFlag = true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment