i am trying to practice on loading data from json files my problem is about when i try to load the sprite path from the json file to load the image icon from the floder that contain it, i manged to do that but by hard code the path but when i try to use variable to hold the path its failed to load any one can help me in that please
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class InventoryItemDataBase : MonoBehaviour
{
public allitemData itemsData = new allitemData();
// Start is called before the first frame update
void Start()
{
TextAsset asset = Resources.Load("ItemData/ItemDataBase") as TextAsset;
itemsData = JsonUtility.FromJson<allitemData>(asset.text);
Debug.Log(fetishitembyid(0).name);
}
public ItemBase fetishitembyid(int id)
{
for (int i = 0; i < itemsData.ItemBase.Count; i++)
{
if (itemsData.ItemBase*.id == id)*
return itemsData.ItemBase*;*
}
return null;
}
}
[System.Serializable]
public class allitemData
{
public List ItemBase = new List();
}
[System.Serializable]
public class ItemBase
{
public int id, Value;
public string name, description;
public static string path;
public static Sprite Icon = Resources.Load(“IconS/Teddy”); // this way the image load
public static Sprite Icon = Resources.Load(path); // this way the image not load
public Sprite sprite = Icon;
public ItemBase()
{
this.id = -1;
}
}
json Data
{
“ItemBase”: [
{
“id”: “0”,
“Value”: “7”,
“name”: “Teddy Bear”,
“description”: “Teddy”,
“path”: “IconS/Teddy”
},
{
“id”: “1”,
“Value”: “5”,
“name”: “UFO”,
“description”: “ufoos”
}]
}
images below
![alt text][1]
_*[1]: https://imgur.com/a/vNvVyBy*_