【发布时间】:2019-04-17 05:25:41
【问题描述】:
我正在开发 3d 跑步类游戏,所以我在 Player GameObject 中附加了两个 AudioSources 组件:
- 用于播放游戏音乐的音频源
- 播放器碰撞声音的AudioSource
在同一个 Player GameObject 上,我分配了两个 AudioSources 来播放这两个声音,但目前只播放 GamePlay 音乐,当它与障碍物碰撞时不会播放 Player 碰撞声音。
两个 AudioSource 都有其分配的 AudioClip。
在与障碍物发生碰撞时,我是这样播放碰撞声音的:
void OnCollisionEnter (Collision other)
{
if (other.transform.CompareTag (GameConstants.TAG_OBSTACLE)) {
Vector3 splashEffectPos = groundCheck.position;
if (splashEffectPos.y < 0.05f)
splashEffectPos.y = 0.05f;
// stop game music
if (SoundManager.Instance.EnableSound) {
gameSoundAS.Play ();
gameMusicAS.Stop ();
// gameSoundAS.PlayOneShot (ballCollisionClip);
}
GameObject splash = Instantiate (splashEffectPrefab, splashEffectPos, Quaternion.identity);
splash.transform.SetParent (GameController.Instance.transform);
GameController.Instance.GameOver ();
gameObject.SetActive (false);
}
}
GamePlay 音乐正常播放,当它与障碍物碰撞时停止播放,但播放器碰撞声音未播放。
【问题讨论】:
标签: unity3d audio-source