I am writing out a Json file in my unity game, however when I play the game the file "Shader.json" gets overwritten with new data.
I am wondering how I can append a timestamp or a increasing number to the file path so that it creates a new Json file each time the data is written.
Here is my code to output the Json data. Edited and working
public class writejson : MonoBehaviour
{
public ShaderValues shader = new ShaderValues("Test123", 2, 155, 100, 30);
JsonData shaderJson;
public static string GetUniqueIdentifier()
{
return System.Guid.NewGuid().ToString();
}
void Start()
{
shaderJson = JsonMapper.ToJson(shader);
Debug.Log(shaderJson);
File.WriteAllText(Application.dataPath + "/Json/ShaderSettings_" + GetUniqueIdentifier() + ".json", shaderJson.ToString());
}
public class ShaderValues
{
public string name;
public int shadertype;
public int red;
public int blue;
public int green;
public ShaderValues(string name, int shadertype, int red, int blue, int green)
{
this.name = name;
this.shadertype = shadertype;
this.red = red;
this.blue = blue;
this.green = green;
}
}
}