1.建一个AudioManager的script文件,挂到空物体上
(1) AudioManager中创建与声音文件相应的AudioClip对象,
public AudioSource characterSound,mainMusic;
public AudioClip explosionSfx,_bounceSfx,_clickSfx,_crashBoxSfx,_crashShieldSfx,_girlDieSfx,_gunShoot,_zombieDie;
(2) 创建播放相应声音文件的方法:
public void PlayGunShoot ()
{ characterSound.PlayOneShot (_gunShoot, 1.0f); }
(3) 在别的类中写触发播放声音的事件:
//如果按了确定键,并且子弹数大于零,调用播放函数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 ();
。。。。。。。。。。。}
网友评论