1.建一個(gè)AudioManager的script文件锭魔,掛到空物體上
(1) AudioManager中創(chuàng)建與聲音文件相應(yīng)的AudioClip對(duì)象笙隙,
public AudioSource characterSound,mainMusic;
public AudioClip explosionSfx,_bounceSfx,_clickSfx,_crashBoxSfx,_crashShieldSfx,_girlDieSfx,_gunShoot,_zombieDie;
(2) 創(chuàng)建播放相應(yīng)聲音文件的方法:
public void PlayGunShoot ()
{ ? ? ? ? ? ? characterSound.PlayOneShot (_gunShoot, 1.0f); ? ? ?}
(3) 在別的類中寫觸發(fā)播放聲音的事件:
//如果按了確定鍵石景,并且子彈數(shù)大于零捐康,調(diào)用播放函數(shù)PlayGunShoot:
if (!hadshoot && Input.GetKey(KeyCode.Space) || Input.GetKeyDown(KeyCode.JoystickButton0) || Input.GetKeyDown(MI_OK) || Input.GetKeyDown(KeyCode.Y) || Input.GetKeyDown(LeTVKeyCode) ) {
hadshoot = true;
if (UIManager._instance._bulletList.Count > 0) {
_direction = transform.position - _player.shootPoint.position;
AudioManager.Instance.PlayGunShoot ();
贞滨。入热。。晓铆。勺良。。骄噪。尚困。。链蕊。事甜。}