- Home /
Calling Json script and displaying the Images within the script
I'm trying to access a Json script, it is in a domain. The script holds a couple of images, which are hyperlinked. I've tried using WWW to access the script, but the image i received was a picture of a huge red question mark. Clearly I'm going about the wrong way with this. So i'm assuming I'm supposed to decode the json script through unity and then display the image with the ability to see next/previous image by clicking? I'm unfamiliar with Json so how about would i call the script and read the the images it's calling?
This is what my code looks like, the code works since I've tried another non Json domain with just an image- and it works perfectly fine.
void Start ()
{
renderer.material.mainTexture = new Texture2D(4,4, TextureFormat.DXT1, false);
url = "http://hosting.xivmedia.com/JsonHome/JSON/more_games.json";
www = new WWW(url);
StartCoroutine(WaitForSeconds(www));
}
IEnumerator WaitForSeconds(WWW www)
{
yield return www;
www.LoadImageIntoTexture(renderer.material.mainTexture as Texture2D);
if (www.error == null)
{
Debug.Log("WWW Ok!: " + www.data);
imageLoaded = true;
}
else
{
Debug.Log("WWW Error: " + www.error);
}
}
void OnGUI()
{
GUI.DrawTexture(new Rect(20, 80, 100, 100), renderer.material.mainTexture as Texture2D, ScaleMode.StretchToFill);
}
s
I assume the WWW
call with the json
URL will give you a text file that you're supposed to decode. Once you have the json file, look at it and see what it contains. I'd guess it'll have the URL to the images, and you'd then kick off other WWW
calls to get each one.
I see, how would i go about decoding it? Also I need my script to be dynamic, since I might add more images to my json file when my game is live.
Your answer
Follow this Question
Related Questions
Dynamically load json data to a game: What are the best practices? 1 Answer
How to Pass a Json as Post Data to WWWForm 2 Answers
What is the best approach to filter large data sets in Unity? 1 Answer
WWWForms and sending data to database dont work 2 Answers
Data Management Issue - How to manage retrieved data from mysql? 0 Answers