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();
5 items get printed from the foreach loop. The below code is one of them
System.String : Piston System.String Piston
Piston
is the key which I'm looking for
But right below the for loop,
when I use this
slider.value = propertyDict[mainText.text].GetSpeed();
I get this error
KeyNotFoundException: The given key was not present in the dictionary.
But key was printed in the for loop. I don't get it.
This is how I initialized
public Dictionary<String, EngineProperty> propertyDict = new Dictionary<String, EngineProperty>();
I have tried replacing everything with String
with string
, and still, it doesn't work.
What do I do?