- Home /
Question by
ShiNoKitsune · Oct 30, 2017 at 03:35 PM ·
jsonfilelitjson
Json file not found after the Build... Help
After I do build of the game when I run it, it can't assece to the Item.json file
Here my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using LitJson;
using System.IO;
public class ItemDatabase : MonoBehaviour {
private List <Item> database = new List<Item> ();
private JsonData itemData;
void Start (){
itemData = JsonMapper.ToObject (File.ReadAllText (Application.dataPath + "/Inventory/StreamingAssets/Items.json"));
ConstructItemDatabase ();
}
public Item FetchItemByID(int id){
for(int i=0;i<database.Count;i++)
if (database [i].ID == id)
return database [i];
return null;
}
void ConstructItemDatabase(){
for(int i=0;i<itemData.Count;i++){
database.Add (new Item ((int)itemData [i] ["id"],
itemData [i] ["title"].ToString (),
(int)itemData [i] ["value"],
itemData [i] ["description"].ToString (),
itemData [i] ["slug"].ToString (), (bool)itemData [i] ["stackable"]));
}
}
}
public class Item{
public int ID { get; set;}
public string Title{ get; set;}
public int Value{ get; set;}
public string Description{ get; set;}
public string Slug{ get; set;}
public Sprite Sprite { get; set;}
public bool Stackable { get; set;}
public Item(int id,string title,int value, string description,string slug, bool stackable)
{
this.ID = id;
this.Title = title;
this.Value = value;
this.Description = description;
this.Slug = slug;
this.Stackable = stackable;
this.Sprite = Resources.Load<Sprite> (slug);
}
public Item(){
this.ID = -1;
}
}
If anyone wants to help I have this questions to: http://answers.unity3d.com/questions/1425146/problem-with-animation-triggring.html
and:
http://answers.unity3d.com/questions/1421791/how-do-i-can-make-this-3rd-person-camera-smoother.html
Comment
Best Answer
Answer by Bilelmnasser · Oct 30, 2017 at 03:58 PM
hi, put your file inside this folder : Application.streamingAssetsPath
itemData = JsonMapper.ToObject (File.ReadAllText (Application.streamingAssetsPath + "/Items.json"));