Unityスクリプト

※上記の広告は60日以上更新のないWIKIに表示されています。更新することで広告が下部へ移動します。

目次

ランダムなパンで繰り返し鳴らし続ける


public class PanChange : MonoBehaviour {
	CriAtomSource source;
	void Start () {
		source = GetComponent<CriAtomSource>();
	}
	void Update () {	
		if(source.status == CriAtomSource.Status.PlayEnd || source.status == CriAtomSource.Status.Stop)
		{
			source.pan3dAngle = Random.Range(-30,30);
			source.Play();	
		}
	}
}

高速にランダムなパンピッチで鳴らし続ける


public class PanChange : MonoBehaviour {
public float duration = 0.02f;
CriAtomSource source;
void Start () {
	source = GetComponent<CriAtomSource>();
}
float time = 0;
void Update () {	
	if(Time.timeSinceLevelLoad > time){
		source.pan3dAngle = Random.Range(-30,30);
		source.pitch = Random.Range(-1200,1200);
		source.Play();	
		time = Time.timeSinceLevelLoad+duration;
       }
   }
}

高速にランダムなパンピッチで鳴らし続けるUnity(参考)


public class PanChange : MonoBehaviour {
public float duration = 0.02f;
public AudioClip clip;
AudioSource source;
void Start () {
	source = GetComponent<AudioSource>();
	source.PlayOneShot(clip);
   }
float time = 0;
void Update () {	
	if(Time.timeSinceLevelLoad > time){
		source.pan = Random.Range(-1f,1f);
		source.PlayOneShot(clip);
		time = Time.timeSinceLevelLoad+duration;
	}
}
}

高速にランダムなピッチでならす(AtomPleyer)

public class PanChange : MonoBehaviour {
public float duration = 0.02f;
CriAtomExPlayer atomPlayer = null;
void Start () {
	atomPlayer = new CriAtomExPlayer(); // AtomExPlayer()作成		
	atomPlayer.SetCue(null,"synth");
   }
float time = 0;
void Update () {	
	if(Time.timeSinceLevelLoad > time){
		atomPlayer.SetPitch(Random.Range(-1200,1200));
		atomPlayer.Start();
		time = Time.timeSinceLevelLoad+duration;
       }
   }
void OnDestroy()
{
	if(atomPlayer != null){
           atomPlayer.Dispose(); // 破棄
           atomPlayer = null;
	}
}
}


ランダムなピッチでならす(AtomPleyerと3DPositioning)


public class PanChange : MonoBehaviour {
public float duration = 0.02f;
public float minDistance = 5f;
public float maxDistance = 30f;
public float dopplerFactor = 0.0f;
CriAtomExPlayer atomPlayer = null;
CriAtomEx3dSource atom3dSource = null;
void Start () {
	atomPlayer = new CriAtomExPlayer(); // AtomExPlayer()作成		
	atom3dSource = new CriAtomEx3dSource();
	atom3dSource.SetMinMaxDistance(minDistance,maxDistance);
	atom3dSource.SetDopplerFactor(dopplerFactor);
	atomPlayer.SetPanType(CriAtomEx.PanType.Pos3d);		
	atomPlayer.SetCue(null,"synth");
	atomPlayer.Set3dSource(atom3dSource);
	atomPlayer.Set3dListener(CriAtomListener.instance.internalListener);
	
	atomPlayer.SetPitch(Random.Range(-1200,1200));
	duration = Random.Range(2,4)*0.2f;
   }
float time = 0;
void Update () {	
	atom3dSource.SetPosition(this.transform.position.x,this.transform.position.y,this.transform.position.z);
	atom3dSource.Update();
	atomPlayer.UpdateAll();
	if(Time.timeSinceLevelLoad > time){
		atomPlayer.Start();
		time = Time.timeSinceLevelLoad+duration;
       }
   }
void OnDestroy()
{
	if(atomPlayer != null){
           atomPlayer.Dispose(); // 破棄
           atomPlayer = null;
		atom3dSource.Dispose();
		atom3dSource = null;
	}
}
}