Unity“无法播放禁用的音频源”

Yifei Xu

每当调用该功能时,我一直在尝试播放效果音,但是我不断收到通知“无法播放禁用的音频源”。我还注意到,即使关闭了声音,声音仍会唤醒。这是我的EffectController类的样子

//--------------------------------------------------------------------------------------------------------------------
//  <copyright file="EffectController.cs" company="ShinjiGames">
//     Copyright (c) ShinjiGames LLC 2016.  All rights reserved.
//  </copyright>
//--------------------------------------------------------------------------------------------------------------------

namespace Assets.Scripts.Effects
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    using GameSettings;
    using UnityEngine;

    /// <summary>
    /// Responsible for audio cues and other add-on effects
    /// </summary>
    public class EffectController : MonoBehaviour
    {
        /// <summary>
        /// The sound that plays whenever the player hits a pickup
        /// </summary>
        public AudioSource PickupChime;

        /// <summary>
        /// The current instance of the effect controller
        /// </summary>
        private static EffectController instance;

        /// <summary>
        /// Get the instance of the effect controller
        /// </summary>
        /// <returns>The instance of the effect controller</returns>
        public static EffectController GetInstance()
        {
            return EffectController.instance;
        }

        /// <summary>
        /// When the player hits a pickup on the given position, plays the chime and add an effect
        /// </summary>
        /// <param name="position">The position of the collision</param>
        public void PickupEffect(Vector3 position)
        {
            this.PickupChime.enabled = true;
            this.PickupChime.PlayOneShot(this.PickupChime.clip);
        }

        /// <summary>
        /// When the players hits a bomb, display the bomb explosion 
        /// </summary>
        /// <param name="position">The origin of the explosion</param>
        public void BombEffect(Vector3 position)
        {
            var explosion = GameObject.Instantiate(PrefabManager.GetIntance().BombExplosionPrefab);
            explosion.GetComponent<BombExplosion>().SetOrigin(position);
        }

        /// <summary>
        /// Initialization for the class
        /// </summary>
        private void Start()
        {
            this.PickupChime.enabled = true;
            this.GetComponent<AudioSource>().enabled = true;

            if (EffectController.instance != null)
            {
                GameObject.Destroy(EffectController.instance.gameObject);
            }

            EffectController.instance = this;
            GameObject.DontDestroyOnLoad(this.gameObject);
        }
    }
}

有人可以帮我吗?我正在慢慢发疯

编辑1:我更新了该类,以便它不使用AudioSource,而拥有AudioSource的自己的组件,而是将其片段插入到提示音中,从而解决了该问题。

麦克风

您可能在检查器中未选中“音频源”。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

从脚本播放音频源

来自分类Dev

音频无法播放pygame

来自分类Dev

Android音频无法播放

来自分类Dev

无法同时播放两个音频源,只有麦克风可以工作。

来自分类Dev

无论如何我都无法禁用自动播放音频文件

来自分类Dev

无论如何我都无法禁用自动播放音频文件

来自分类Dev

iOS,WAV音频无法播放

来自分类Dev

AVAudioPlayer无法播放音频

来自分类Dev

Firefox无法播放音频

来自分类Dev

Swift 3音频无法播放

来自分类Dev

音频无法在 React 中播放

来自分类Dev

禁用WebView中的自动音频播放

来自分类Dev

Unity WebGL:为什么使用下载的 Mp3 或 OGG 文件无法播放音频?

来自分类Dev

如何停止在Chrome中播放重复的音频源

来自分类Dev

从url播放音频源不起作用

来自分类Dev

jQuery同时播放HTML5音频源

来自分类Dev

哪个“ pactl”:音频源“正在播放”一个

来自分类Dev

jQuery同时播放HTML5音频源

来自分类Dev

以 blob 作为源播放音频时出现 DOMException

来自分类Dev

XCode 5中的音频无法播放

来自分类Dev

iOS 7:音频无法在后台播放

来自分类Dev

音轨JS功能无法播放或暂停音频

来自分类Dev

无法识别播放哪个音频文件

来自分类Dev

Gstreamer无法通过rtspsrc播放音频

来自分类Dev

AVAudioPlayer无法播放音频Swift

来自分类Dev

音频无法播放。Django,DEBUG = False

来自分类Dev

碰撞后无法播放音频片段

来自分类Dev

音频文件无法在reactjs中播放

来自分类Dev

音频无法在Angular 7中播放