Unity技术分享

U3D声音

2017-08-11  本文已影响0人  仰望天堂_e6c6

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 ();

。。。。。。。。。。。}

2. 在unity中将音频变量和声音文件对应起来

上一篇 下一篇

猜你喜欢

热点阅读