Accessing a Json FILE and using it to set variables

Just to make this clear i’m not wanting to set a class and turn it into a json file I want to access parts of an array from an already created actual .json i tried to lay out as best I could what i was trying to do in the photos. If anyone who wants to help has a question let me know :slight_smile:

Yes i know Towers doesn’t exist in the script… its just what i used to replicate where the json object Towers would go.

The json file in sublime text

The script I need to access the json file

Not sure what you want, but I assume you want to access a .json file stored on your computer and read properties from it. Try the following:

 JObject Towers; // <---------- Add this

void Start () {
	useTowerId = Random (0,3);

	// Load Json Towers
	LoadJson();
	
	// Your other code
	//...
}
    // Add this function
    public void LoadJson()
    {
        using (StreamReader r = new StreamReader("fileName.json"))
        {
            string towerString = r.ReadToEnd();
            Towers = JObject.Parse(towerString );
        }
    }

I think I found my own solution just seems to difficult for what i’m trying to do, just thought i’d try json since I use to use it for javascript websites all the time, but for now a switch statement will work even though it may not be that effective.