Dictionary: User-Choice Data
GameData.cs: Create a C# Dictionary
DictionaryGameData.cs Version 2
private Dictionary<string,string> choiceData = new Dictionary< string,string>();
public void SaveChoice( string choiceKey, string choiceValue)
{
if (choiceData.ContainsKey(choiceKey))
{
choiceData[choiceKey] = choiceValue; //change stored value
Debug.Log("Choice Changed" + choiceKey + " : " + choiceValue);
}
else
{
choiceData.Add(choiceKey, choiceValue); //adds key,value pair
Debug.Log("Choice Data Created" + choiceKey + " : " + choiceValue);
}
}
public string GetChoice( string choiceKey)
{
string choiceValue = "None";
choiceData.TryGetValue(choiceKey, out choiceValue);
Debug.Log("Choice Data Accessed" + choiceKey + " : " + choiceValue);
return choiceValue;
}
Last updated