Skip to content

Instantly share code, notes, and snippets.

@edom18
Created May 27, 2014 10:06
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 edom18/d095f1e6c7893041d9b6 to your computer and use it in GitHub Desktop.
Save edom18/d095f1e6c7893041d9b6 to your computer and use it in GitHub Desktop.
[Unity] Unityで音を再生する ref: http://qiita.com/edo_m18/items/31771c2afc065d764fbf
// AudioSourceがアタッチされたGameObject
void OnCollisionEnter(Collision collision) {
AudioSource audioSource = gameObject.GetComponent<AudioSource>();
audioSource.PlayOneShot(anySE);
}
// あるいは、audioSourceのclipプロパティに設定して再生
void OnCollisionEnter(Collision collision) {
AudioSource audioSource = gameObject.GetComponent<AudioSource>();
audioSource.clip = anySE;
auidoSource.Play();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment