Hello everyone, I’m new in Unity.
I’m trying to create some .json files but when I use the “File.*” expression this return me this error: ‘File’ is inaccessible due to its protection level. I have searched for access method error but I can’t find nothing. What I can do?
Thanks for the help.
Here the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.IO;
public class TestWriter : MonoBehaviour
{
[System.Serializable]
public class InfoPlayer
{
public string name;
public float health;
}
public InfoPlayer player = new InfoPlayer();
public void OutputJSON()
{
string output = JsonUtility.ToJson(player);
string path = Application.dataPath+"/text.json";
print(path);
File.WriteAllText(path,output);
}
}