
TOSHICHAN
Unityでスクリプト&簡単な実装サイト
音再生&複数音再生
public AudioSource _audioSource;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown ("space")) {
//再生
_audioSource.Play ();
}
}
private AudioSource sound01;
private AudioSource sound02;
void Start () {
//AudioSourceコンポーネントを取得し、変数に格納
AudioSource[] audioSources = GetComponents<AudioSource>();
sound01 = audioSources[0];
sound02 = audioSources[1];
}
void Update () {
//指定のキーが押されたら音声ファイル再生
if(Input.GetKeyDown(KeyCode.K)) {
sound01.PlayOneShot(sound01.clip);
}
if(Input.GetKeyDown(KeyCode.L)) {
sound02.PlayOneShot(sound02.clip);
}
}
単発再生
複数再生
※Play On Awakeのチェックを外すこと!!!
