I’m making a scoreboard like this
I successfully converted my string data to json using this line of code
//1 = blue circle, 2 = red circle
string jsonString = "[1, 1, 1, 2, 1, 1, 1, 2, 1, 2, 1, 1, 1, 2, 1, 1]"; //sample data
ExampleClass dataParser = new ExampleClass();
dataParser.dataToParse = jsonString;
//Convert to Json
string exampleClassToJson = JsonUtility.ToJson(dataParser);
Debug.Log(exampleClassToJson);
ExampleClass obj = JsonUtility.FromJson<ExampleClass>(exampleClassToJson);
//Loop over it
for (int i = 1; i < obj.dataToParse.Length - 1; i += 3)
{
char indivisualChar = obj.dataToParse[i];
}
[Serializable]
public class ExampleClass
{
public string dataToParse;
}
Now here is my script
BetBoard_Test.cs
```csharp
**[B]//Scoreboard
[SerializeField] protected GameObject prefab_big_road = null;
[SerializeField] Transform pos_big_road = null;
string jsonString = "[1, 1, 1, 2, 1, 1, 1, 2, 1, 2, 1, 1, 1, 2, 1, 1]"; //sample data
private void Start()
{
ExampleClass dataParser = new ExampleClass();
dataParser.dataToParse = jsonString;
//Convert to Json
string exampleClassToJson = JsonUtility.ToJson(dataParser);
Debug.Log(exampleClassToJson);
ExampleClass obj = JsonUtility.FromJson<ExampleClass>(exampleClassToJson);
//Loop over it
for (int i = 1; i < obj.dataToParse.Length - 1; i += 3)
{
char indivisualChar = obj.dataToParse[i];
int j = 0;
if(j < rh.Const._HISTORY_COUNT_ * rh.Const._HISTORY_HEIGHT_)
{
//lets increment it
j++;
//instantiate the sprite
GameObject o = Instantiate(prefab_big_road) as GameObject;
o.transform.SetParent(pos_big_road);
o.transform.localScale = Vector3.one; //(1,1,1)
int x = j % rh.Const._HISTORY_COUNT_;
int y = j / rh.Const._HISTORY_COUNT_;
float xl = 2.3f;
float yl = -26.69f;
o.transform.localPosition = new Vector3(x * xl, y * yl, 0f);
o.GetComponent<UISprite>().spriteName = indivisualChar == 1 ? "layout_player_bigline-01" : "layout_banker_bigline-01";
NGUITools.SetActive(o, true);
}
}
}
void DeleteChildrens(Transform t)
{
NGUITools.DestroyChildren(t);
}
}
[Serializable]
public class ExampleClass
{
public string dataToParse;
}[/B]**
** __**ConstantValue.cs**__ __**
csharp__
**public const int HISTORY_COUNT = 70;
public const int HISTORY_HEIGHT = 6;
__**__ <strong>__**PlayInfo.cs**__</strong> <strong>__**
csharp**
public int[] BIG_ROAD = new int[Const.HISTORY_COUNT * Const.HISTORY_HEIGHT ];
```
Those code above give me this ouput
And what most bothering me here is that the prefab that is clone are all red there’s no blue one even though i provided this string jsonString = "[1, 1, 1, 2, 1, 1, 1, 2, 1, 2, 1, 1, 1, 2, 1, 1]__"
red = 2 , blue = 1