【问题标题】:Same GameObject Two AudioSources Not Playing Their AudioClips - Unity相同的游戏对象两个音频源不播放他们的音频剪辑 - Unity
【发布时间】:2019-04-17 05:25:41
【问题描述】:

我正在开发 3d 跑步类游戏,所以我在 Player GameObject 中附加了两个 AudioSources 组件:

  1. 用于播放游戏音乐的音频源
  2. 播放器碰撞声音的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


    【解决方案1】:

    好的,我自己解决了这个问题。如果 GameObject 被禁用,则其 AudioSources 无法播放。

    在上面的 OnCollisionEnter 方法中,我禁用了我的 Player GameObject,因此 AudioSource 不会产生任何声音。

    【讨论】:

    • 如果您解决了自己的问题,您应该选择您的答案作为解决方案,以便未来的人知道您是如何解决的。
    • 由于堆栈溢出的等待时间,我没有选择此选项为真 - 同时我无法将我的答案标记为正确 - 我需要等待 2 天
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-11
    • 1970-01-01
    • 1970-01-01
    • 2020-01-20
    • 2020-09-24
    • 1970-01-01
    • 2011-03-03
    相关资源
    最近更新 更多