- Home /
The question is answered, right answer was accepted
Changing UI text to text from json file
Hello!
I have a script which gets data from a JSON file, then changes the UI text to data from the JSON file.
if(name == "Province ireland"){
path = Application.streamingAssetsPath + "/Provinces/Ireland.json";
}
if(name == "Province wales"){
path = Application.streamingAssetsPath + "/Provinces/Wales.json";
}
Debug.Log(path);
jsonString = File.ReadAllText(path);
Debug.Log(jsonString);
Province IRELAND = JsonUtility.FromJson<Province>(jsonString);
provinceNameText = provinceNameText.GetComponent<TextMesh>();
provinceNameTextUI = provinceNameTextUI.GetComponent<Text>();
provinceNameText.text = IRELAND.name;
provinceNameTextUI.text = IRELAND.name;
Debug.Log(provinceNameTextUI.text);
Debug.Log(provinceNameText.text);
Debug.Log(IRELAND.name);
When i runn the game, the console logs the correcct name from the json file, when i click on the ireland gameobject, the ui text says ireland for a second, then changes to wales
Here is the JSON file:
{
"id": "2",
"name": "Wales",
"R":"100", "G":"0", "B":"0",
"terrain_type":"plains",
"adjacencies":[],
"prosperity":1.0,
"owner": "Great Britan"
}
Any Ideas? Thanks in advance!
Can you show the full log? What does the statement on line 17 print?
Follow this Question
Related Questions
Create a glossary using Simple JSON, loading data dynamically 1 Answer
How to send text in a json file in mail.body? 0 Answers
JsonUtility deserialization via JSON file doesn't work on WWW, works on File.ReadAllText 1 Answer
using json file for waypoints for vehicle in unity project. 0 Answers
Litjson autoformat 1 Answer