Question by
aan_comel · Oct 27, 2016 at 02:53 AM ·
instantiatejsonsimplearray of gameobjects
Display Array GameObject store in Simple JSON
Hello, please help me to convert simpleJSON database to display gameObject. I want to display PIC : 1
How to convert type string into GameObject[] ?
Simple JSON database, dialog.txt
[
{
ID: 1,
CHAPTER : "Prologue",
BG : "Garage",
PIC : 1,
TXT: "Hello."
}
]
Charachter.cs Class
using UnityEngine;
using System.Collections;
using SimpleJSON;
public class characters : MonoBehaviour {
JSONNode node;
public GameObject[] charachter;
void Start() {
TextAsset cha = Instantiate (Resources.Load("dialog")) as TextAsset;
node = JSON.Parse (cha.text);
//What code do I use to call the charachter "PIC : 1"?
}
}
Comment
Best Answer
Answer by aan_comel · Oct 27, 2016 at 03:33 AM
I think this is the way. I put the image in resource file and name it "1.png"
GetComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>(node[0]["PIC"].Value);