作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
每当调用该功能时,我一直在尝试播放效果音,但是我不断收到通知“无法播放禁用的音频源”。我还注意到,即使关闭了声音,声音仍会唤醒。这是我的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);
}
}
}
最佳答案
您可能在检查器中未选中“音频源”。
关于c# - unity “Can not play a disabled audio source”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39222224/
我是一名优秀的程序员,十分优秀!