Hi there,
I’m new to Unity and just beginning my programming experience, hence I’m asking for something probably not so difficult (?), but I’ve no clue how to tackle that…
I’ve a web server and a php file generating a JSON file.
I’d like to read that JSON file in and display it (data) on the screen (GUI ?).
Could someone tell me how this can be done?
I guess I’d need a JSON parser, but what to do next with the data to have it displayed?
Yes, you can find some good implementations of the parsers in the web, for example at GitHub, I think.
When you extract a data what you need you will have a different ways for showing it on a screen. Tme most quick is draw a Label in OnGUI() method of any script assigned to some gameobject.
For example, write shuch script and assign it to any object in scene:
using UnityEngine;
using System;
class MyGUIClass : MonoBehaviour
{
string data = "here should be an extacted data from JSON";
void OnGUI() {
GUI.Label(new Rect(100, 100, 300, 100), data);
}
}
I presume (correct me) GUI.label should be wrapped with some sort of for each loop so a label could be generated for each element in JSON?
And from what I learned Unity 4.6 uses new UI with canvas as a parent for other GUI elements. What process would be for that new UI?