やまめも

【 ゲーム開発・日々のことについて 】

Sfx[8].clip = BreakDoorClip[n];

AudioSource.clipでclipを変更

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class AudioManager : MonoBehaviour {


	public AudioSource MusicBackground;
	public AudioSource[] Sfx;

	public AudioClip AudioMenuScreen;

	public AudioClip ButtonOKClip;
	public AudioClip ButtonBackClip;
	public AudioClip ButtonCancelClip;
	public AudioClip GunShootClip;
	public AudioClip RescueClip;
	public AudioClip PickUpItemClip;
	public AudioClip ShootedClip;
	public AudioClip GetScoreClip;
	public AudioClip[] BreakDoorClip;

	public static AudioManager instance = null;
	void Awake (){
		if(instance == null){
			instance = this;
		}
	}
	void Start () {
		MusicBackground.clip = AudioMenuScreen;
		MusicBackground.Play();

	}
	public void AudioMenu(){
		MusicBackground.clip = AudioMenuScreen;
		MusicBackground.Play();
	}
	public void ButtonOKSound(){
		Sfx[0].Play();
	}
	public void ButtonBackSound(){
		Sfx[1].Play();
	}
	public void ButtonCancelSound(){
		Sfx[2].Play();
	}
	public void GunShootSound(){
		Sfx[3].Play();
	}
	public void RescueSound(){
		Sfx[4].Play();
	}
	public void PickUpItemSound(){
		Sfx[5].Play();
	}
	public void ShootedSound(){
		Sfx[6].Play();
	}
	//?
	public void GetScoreSound(){
		Sfx[7].Play();
	}
	// 8,9,10
	public void BreakDoorSound(){
		int n = Random.Range(0, 3);
		// 以下ではエラー
		// Sfx[8].GetComponent<AudioSource>().audio = BreakDoorClip[n];
		Sfx[8].clip = BreakDoorClip[n];
		Sfx[8].Play();
	}
}