2016-08-30 33 views
1

無論何時調用該函數,我一直試圖播放效果聲音,但是我總是收到「無法播放禁用的音頻源」通知。我也注意到,儘管我已經關閉了聲音,但聲音仍在播放。這是我的EffectController類看起來像Unity「無法播放禁用的音頻源」

//-------------------------------------------------------------------------------------------------------------------- 
// <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自己的組件,並採取在剪輯的鐘聲相反,它解決了問題。

回答

1

您可能在檢查員中未選中音頻源。