Unity3d 为什么';是否加载该文件?

Unity3d 为什么';是否加载该文件?,unity3d,Unity3d,我有一个问题,json悄悄地保存了文件,当你需要下载它时,什么都不会出来。当你开始游戏的时候,所有的参数都会变假,我不明白为什么。如果有人能帮忙,我会很高兴的。此外,如果代码中有不清楚的地方,我将解释代码的责任 对于下面是保存文件的代码 ` 私有字符串路径; 公共整数[]质量={30,25,15,10,5}; 公共图书馆; 公共bool ItTrue=false; 公共int q=0; 公共整数i=0; 公共国际兰特; 公共整数; 公共整数合计; 公共货币; 公共转换pos; 公共精灵[]角色;

我有一个问题,json悄悄地保存了文件,当你需要下载它时,什么都不会出来。当你开始游戏的时候,所有的参数都会变假,我不明白为什么。如果有人能帮忙,我会很高兴的。此外,如果代码中有不清楚的地方,我将解释代码的责任 对于下面是保存文件的代码

`

私有字符串路径;
公共整数[]质量={30,25,15,10,5};
公共图书馆;
公共bool ItTrue=false;
公共int q=0;
公共整数i=0;
公共国际兰特;
公共整数;
公共整数合计;
公共货币;
公共转换pos;
公共精灵[]角色;
private Save sv=new Save();
无效唤醒()
{
Money=PlayerPrefs.GetInt(“Money_S”,0);
}
void Start()
{
PlayerPrefs.SetInt(“NumTrue”,i);
PlayerPrefs.SetInt(“Money_S”,Money);
Money=PlayerPrefs.GetInt(“Money_S”,0);
货币+=50;
#如果UNITY\u ANDROID&!UNITY\u编辑器
path=path.Combine(Application.persistentDataPath,“Save.json”);
#否则
path=path.Combine(Application.dataPath,“Save.json”);//文件的路径
#恩迪夫
foreach(以质量计的var项目)
{
合计+=项目;
}
Num=UnityEngine.Random.Range(0,总计);
对于(;i如果(Num我认为你的主要问题是

sv = JsonUtility.FromJson<Save>(File.ReadAllText(path)); // присваеваем 
sv.Persi = Persi;

总的来说,我建议大家看看如何在多个场景之间转发这些值,而不必永久性地执行FileIO操作

    private Save sv = new Save();

    public bool[] Persi;

    private string path;
    private string path2;

    
    public GameObject[] Players;
    public bool[] ItSkin;
    public int Num;
    public Vector2 PosActive;
    private int NumPlayer;
    public int q;
    
    public Vector2 PosNotActive;

    public int NumberPlayer = 0;
    public GameObject NotSkin;
    public int bla = 0;
    void Awake()
    {
        q = PlayerPrefs.GetInt("NumTrue" , 0);
        //Persi[q] = true;  
        
    }
    void Start()
    {

        

#if UNITY_ANDROID && !UNITY_EDITOR
        path = Path.Combine(Application.persistentDataPath, "Save.json");
        
#else
        path = Path.Combine(Application.dataPath, "Save.json"); // путь файла

#endif
        
        if (File.Exists(path))//если файл есть
        {
            sv = JsonUtility.FromJson<Save>(File.ReadAllText(path)); // присваеваем 

            Debug.Log("присвоили");
        }
        else
        {

        }
        for(int e = 0; e < Persi.Length; e++){
            Debug.Log(Persi[e]);
        }


    }
    public void PersMas(){
        
    }
#if UNITY_ANDROID && !UNITY_EDITOR
private void OnApplicationPause(bool pause){
            PlayerPrefs.SetInt("PlayerNum", NumberPlayer);
            

        }
#endif

    private void OnApplicationQuit()
    {
        
        PlayerPrefs.SetInt("PlayerNum", NumberPlayer); 
       
    }
    
    void Update()
    {
        sv = JsonUtility.FromJson<Save>(File.ReadAllText(path)); // присваеваем 
        sv.Persi = Persi;
        //Persi[q] = true;
        Num = PlayerPrefs.GetInt("Num" , 0);
        PlayerPrefs.SetInt("PlayerNum", NumberPlayer);

        
        if(bla == 16 && NumPlayer == 16){
            bla = 0;
            NumberPlayer = 0;
        }
        
    }

    public void Next(){
        switch(bla){
            case 0:
                bla++;
                NumPlayer = 1;
                if(Persi[0] == false){
                    NotSkin.SetActive(true);
                }
                else{
                    NumberPlayer = 1;
                    NotSkin.SetActive(false);
                }
                
                Players[0].SetActive(false);
                Players[1].SetActive(true);
                break;
            case 1:
                bla++;
                NumPlayer = 2;
                if(Persi[1] == false){
                    NotSkin.SetActive(true);
                }
                else{
                    NumberPlayer = 2;
                    NotSkin.SetActive(false);
                }
                Players[1].SetActive(false);
                Players[2].SetActive(true);
                break;
            case 2:
                bla++;
                NumPlayer = 3;
                if(Persi[2] == false){
                    NotSkin.SetActive(true);
                }
                else{
                    NumberPlayer = 3;
                    NotSkin.SetActive(false);
                }
                Players[2].SetActive(false);
                Players[3].SetActive(true);
                break;
            case 3:
                bla++;
                NumPlayer = 4;
                if(Persi[3] == false){
                    NotSkin.SetActive(true);
                }
                else{
                    NumberPlayer = 4;
                    NotSkin.SetActive(false);
                }
                Players[3].SetActive(false);
                Players[4].SetActive(true);
                break;
            case 4:
                bla++;
                NumPlayer = 5;
                if(Persi[4] == false){
                    NotSkin.SetActive(true);
                }
                else{
                    NumberPlayer = 5;
                    NotSkin.SetActive(false);
                }
                Players[4].SetActive(false);
                Players[5].SetActive(true);
                break;
            case 5:
                bla++;
                NumPlayer = 6;
                if(Persi[5] == false){
                    NotSkin.SetActive(true);
                }
                else{
                    NumberPlayer = 6;
                    NotSkin.SetActive(false);
                }
                Players[5].SetActive(false);
                Players[6].SetActive(true);
                break;
            case 6:
                bla++;
                NumPlayer = 7;
                if(Persi[6] == false){
                    NotSkin.SetActive(true);
                }
                else{
                    NumberPlayer = 7;
                    NotSkin.SetActive(false);
                }
                Players[6].SetActive(false);
                Players[7].SetActive(true);
                break;
            case 7:
                bla++;
                NumPlayer = 8;
                if(Persi[7] == false){
                    NotSkin.SetActive(true);
                }
                else{
                    NumberPlayer = 8;
                    NotSkin.SetActive(false);
                }
                Players[7].SetActive(false);
                Players[8].SetActive(true);
                break;
            case 8:
                bla++;
                NumPlayer = 9;
                if(Persi[8] == false){
                    NotSkin.SetActive(true);
                }
                else{
                    NumberPlayer = 9;
                    NotSkin.SetActive(false);
                }
                Players[8].SetActive(false);
                Players[9].SetActive(true);
                break;
            case 9:
                bla++;
                NumPlayer = 10;
                if(Persi[9] == false){
                    NotSkin.SetActive(true);
                }
                else{
                    NumberPlayer = 10;
                    NotSkin.SetActive(false);
                }
                Players[9].SetActive(false);
                Players[10].SetActive(true);
                break;
            case 10:
                bla++;
                NumPlayer = 11;
                if(Persi[10] == false){
                    NotSkin.SetActive(true);
                }
                else{
                    NumberPlayer = 11;
                    NotSkin.SetActive(false);
                }
                Players[10].SetActive(false);
                Players[11].SetActive(true);
                break;
            case 11:
                bla++;
                NumPlayer = 12;
                if(Persi[11] == false){
                    NotSkin.SetActive(true);
                }
                else{
                    NumberPlayer = 12;
                    NotSkin.SetActive(false);
                }
                Players[11].SetActive(false);
                Players[12].SetActive(true);
                break;
            case 12:
                bla++;
                NumPlayer = 13;
                if(Persi[12] == false){
                    NotSkin.SetActive(true);
                }
                else{
                    NumberPlayer = 13;
                    NotSkin.SetActive(false);
                }
                Players[12].SetActive(false);
                Players[13].SetActive(true);
                break;
            case 13:
                bla++;
                NumPlayer = 14;
                if(Persi[13] == false){
                    NotSkin.SetActive(true);
                }
                else{
                    NumberPlayer = 14;
                    NotSkin.SetActive(false);
                }
                Players[13].SetActive(false);
                Players[14].SetActive(true);
                break;
            case 14:
                bla++;
                NumPlayer = 15;
                if(Persi[14] == false){
                    NotSkin.SetActive(true);
                }
                else{
                    NumberPlayer = 15;
                    NotSkin.SetActive(false);
                }
                Players[14].SetActive(false);
                Players[15].SetActive(true);
                break;
            case 15:
                bla++;
                NumPlayer = 16;
                if(Persi[15] == false){
                    NotSkin.SetActive(true);
                }
                else{
                    NumberPlayer = 0;
                    NotSkin.SetActive(false);
                }
                Players[15].SetActive(false);
                Players[0].SetActive(true);
                break;          
            
            default:
                break;
        }
    }
    
        public void CloseSkin(){
        SceneManager.LoadScene("menu");
    }

    [Serializable]
    public class Save
    {
        public bool[] Search;
        public bool[] Persi;
    }
sv = JsonUtility.FromJson<Save>(File.ReadAllText(path)); // присваеваем 
sv.Persi = Persi;
public bool[] Persi => sv.Persi;