foreach (KeyValuePair<String, EngineProperty> kvp in propertyDict)
{
Debug.Log(kvp.Key.GetType()+" : "+ kvp.Key+ " "+ mainText.text.GetType()+ " "+ mainText.text);
}
slider.value = propertyDict[mainText.text].GetSpeed();
从 foreach 循环中打印了 5 个项目。下面的代码就是其中之一
System.String : Piston System.String Piston
Piston
是我要找的钥匙
但就在 for 循环的正下方,
当我使用这个
slider.value = propertyDict[mainText.text].GetSpeed();
我收到这个错误
KeyNotFoundException: The given key was not present in the dictionary.
但是 key 是在 for 循环中打印的。我不明白。
这就是我初始化的方式
public Dictionary<String, EngineProperty> propertyDict = new Dictionary<String, EngineProperty>();
String
我已经尝试用替换所有内容string
,但它仍然不起作用。
我该怎么办?