Skip to content

Instantly share code, notes, and snippets.

@tatmos
Created August 7, 2013 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tatmos/6179144 to your computer and use it in GitHub Desktop.
Save tatmos/6179144 to your computer and use it in GitHub Desktop.
Unity x ADX2LE 【効能】BGMがシーン切り替え時に自動停止します。 【使い方】BGM等の長めの音にAtomSource付きオブジェクトにコンポーネントとして貼付ける。 【使いどころ】シーン切り替え時のサウンド演出  エンベロープを長めにするとフェードアウトする演出になり、再生音が止まると自動消滅する。  シーンのつなぎ目で音がブチブチ切れないのでちょっと良い感じになります。 【補足】シーンをまたぐ場合、CriWareLibraryInitializerとCRIWAREはDont Destroy On Loadをチェックしておきます。
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