C# 声音未添加到字典容器

C# 声音未添加到字典容器,c#,audio,xna,C#,Audio,Xna,我正在用XNA制作声音,我想把它们添加到字典中,这样我就可以随时存储和调用它们。例如,存储跳跃声音,在玩家类中跳跃时调用它 代码如下: this.soundEffectInfo = new SoundEffectInfo(this, "BackgroundSound", "Assets\\Sounds\\RaceSound", 0.9f, 20, 20, true); soundManager.add(soundEffectInfo); soundEffectInfo.SOUNDEFFECT.

我正在用XNA制作声音,我想把它们添加到字典中,这样我就可以随时存储和调用它们。例如,存储跳跃声音,在玩家类中跳跃时调用它

代码如下:

this.soundEffectInfo = new SoundEffectInfo(this, "BackgroundSound", "Assets\\Sounds\\RaceSound", 0.9f, 20, 20, true);

soundManager.add(soundEffectInfo);
soundEffectInfo.SOUNDEFFECT.Play();

this.soundEffectInfo = new SoundEffectInfo(this, "JumpSound", "Assets\\Sounds\\JumpSound", 0.9f, 20, 20, true);
soundManager.add(soundEffectInfo);
soundEffectInfo
是一个
soundEffectInfo
对象,它接受一个
SoundEffectInstance
SoundManager
是这些实例的类容器

我得到的错误是:

RATEV2.exe中发生类型为“System.NullReferenceException”的未处理异常
其他信息:对象引用未设置为对象的实例


闻起来好像你没有引用你的字典。

我需要查看整个类来了解问题所在,但与其将所有音效放在一个字典中,不如尝试创建一个静态类来保存对所有音效文件的引用,我在游戏中是这样做的:

    public static class SoundEffects
    {
           public static SoundEffect jump; 

           public static void LoadSounds(ContentManager content)
           {
                jump = content.Load<SoundEffect>("location); 
           }
    }
公共静态类SoundEffects
{
公共静态音效跳跃;
公共静态void LoadSounds(ContentManager内容)
{
跳转=content.Load(“位置”);
}
}

然后,您可以只调用
SoundEffects.jump.Play();
任何需要的地方,您也可以编写一个静态SoundManager类来调整音量,并在需要时调整播放时间。

您的错误具体发生在何处?我没有看到调用跳转声音的代码。。。