I want to make a list of all the achievements the player can earn in my game. With the code bellow I retrieve the achievements from the server and I've made a scroll list in Unity to show them but only the first row appears. I'd like to show the name, description and currency of all of them. I'd also like to change the color of the achievements the player has earned if bool earned variable is true.
I've attached below an image of the list I'd like to appear and a screenshot of the scrollview I have in the hierarchy.
new GameSparks.Api.Requests.LogEventRequest ()
.SetEventKey ("LISTACHIEVEMENTS")
.Send ((response) => {
if(!response.HasErrors)
{
Debug.Log("List Achivements Loaded Sucessfully...");
GSData scriptData = response.ScriptData;
List<GSData> achievements = scriptData.GetGSDataList("achievements"); //retrieve the array of objects
for (int i = 0; i < achievements.Count; i++)
{
string name = achievements[i].GetString("name");
string description = achievements[i].GetString("description");
int? currency1Award = achievements[i].GetInt("currency1Award");
bool? earned = achievements[i].GetBoolean("earned");
Debug.Log(name);
Debug.Log(description);
Debug.Log(currency1Award);
Debug.Log(earned);
GameObject tempFile = Instantiate (filePrefab, contentRef.transform);
Text tempName = tempFile.transform.GetChild(0).GetComponent<Text>();
Text tempDescription = tempFile.transform.GetChild(1).GetComponent<Text>();
Text tempCurrency1Award = tempFile.transform.GetChild(2).GetComponent<Text>();
tempName.text = name;
tempDescription.text = description;
tempCurrency1Award.text = currency1Award.ToString();
}
}
else
{
Debug.Log("Error Loading Achivements...");
}
});
See Question&Answers more detail:os