【发布时间】:2018-04-08 08:18:34
【问题描述】:
在我的项目中,我有两个场景'Opening''Main'。
如果一段时间内没有按键或完成任务,
它会回到开场场景并重新开始。
它有效,开始场景 -> 主场景
并转到主场景 -> 开幕场景
但是“主场景 -> 开场”以及当我再次尝试进入主场景时,
它显示了这些错误。 :
ArgumentException: An element with the same key already exists in the dictionary.
System.Collections.Generic.Dictionary`2[System.Int32,System.Collections.Generic.Dictionary`2[KeyDelayData+Delay,UnityEngine.Sprite]].Add (Int32 key, System.Collections.Generic.Dictionary`2 value) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:404)
Note.Init () (at Assets/Scripts/Music/Note.cs:22)
ManagerChat.Awake () (at Assets/Scripts/Chatting/ManagerChat.cs:315)
ArgumentException: An element with the same key already exists in the dictionary.
System.Collections.Generic.Dictionary`2[System.Int32,UnityEngine.AudioClip].Add (Int32 key, UnityEngine.AudioClip value) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:404)
SoundManager.Awake () (at Assets/Scripts/Music/SoundManager.cs:16)
这对我来说似乎是一些重置变量的问题,但我不知道这是什么意思
我能做些什么来解决这个问题?
【问题讨论】:
-
你在使用
Dictionary吗?如果没有,那么您正在使用的插件在尝试再次添加现有密钥时正在使用字典。 -
是的,我在几个脚本上使用 Dictionary。
-
我使用 DictionaryValue.Clear (); 修复第二个但我仍然无法修复第一个
-
我通过像第二个一样简单地清除值来修复第一个,谢谢!