C# Can';t在游戏关闭后保存数据以加载(Unity3d)

C# Can';t在游戏关闭后保存数据以加载(Unity3d),c#,unity3d,save,C#,Unity3d,Save,我想保存一些变量的值。我想把它保存到文件中,但它不起作用。所以现在我用另一种方式尝试。但它也不会保存数据。。。如果我启动模拟I Unity,更改变量的值,停止模拟,然后再次启动,我就有了旧的变量值 void OnEnable() { LoadFromFile(); } void OnDisable() { SaveToFile(); } public void SaveTo

我想保存一些变量的值。我想把它保存到文件中,但它不起作用。所以现在我用另一种方式尝试。但它也不会保存数据。。。如果我启动模拟I Unity,更改变量的值,停止模拟,然后再次启动,我就有了旧的变量值

    void OnEnable()
    {        
        LoadFromFile();
    }

    void OnDisable()
    {        
        SaveToFile();
    }

    public void SaveToFile()
    {
        GameObject gameManagerObject = GameObject.FindGameObjectWithTag("GAMEMANAGER");
        GAMEMANAGER gameManager = gameManagerObject.GetComponent<GAMEMANAGER>();
        IndicatorsInfo indicatorsInfo = new IndicatorsInfo();

        PlayerPrefs.SetFloat("my_setting", indicatorsInfo.walkSpeedTemfFile);
    }

    public void LoadFromFile()
    {
        GameObject gameManagerObject = GameObject.FindGameObjectWithTag("GAMEMANAGER");
        GAMEMANAGER gameManager = gameManagerObject.GetComponent<GAMEMANAGER>();

        gameManager.walkSpeedTemp = PlayerPrefs.GetFloat("my_setting");
    }

    [Serializable]
    class IndicatorsInfo
    {
        public float walkSpeedTemfFile;
    }
void OnEnable()
{        
LoadFromFile();
}
无效可禁用()
{        
SaveToFile();
}
public void SaveToFile()
{
GameObject gameManagerObject=GameObject.FindGameObjectWithTag(“GAMEMANAGER”);
GAMEMANAGER GAMEMANAGER=gameManagerObject.GetComponent();
indicatorInfo indicatorInfo=新的indicatorInfo();
PlayerPrefs.SetFloat(“我的设置”,指示符号info.walkSpeedTemfFile);
}
公共void LoadFromFile()
{
GameObject gameManagerObject=GameObject.FindGameObjectWithTag(“GAMEMANAGER”);
GAMEMANAGER GAMEMANAGER=gameManagerObject.GetComponent();
gameManager.walkSpeedTemp=PlayerPrefs.GetFloat(“我的设置”);
}
[可序列化]
类指示符信息
{
公众浮标竞走快车道;
}
使用
new
关键字时,您正在创建
indicatorInfo
new实例。您保存了
indicatorInfo.walkSpeedTemfFile
来自该new实例,而没有为您创建的新
indicatorInfo
指定

可能您正试图做的是从编辑器中保存值

GameObject gameManagerObject = GameObject.FindGameObjectWithTag("GAMEMANAGER");
GAMEMANAGER gameManager = gameManagerObject.GetComponent<GAMEMANAGER>();
PlayerPrefs.SetFloat("my_setting", gameManager.walkSpeedTemp);
GameObject gameManagerObject=GameObject.FindGameObjectWithTag(“GAMEMANAGER”);
GAMEMANAGER GAMEMANAGER=gameManagerObject.GetComponent();
PlayerPrefs.SetFloat(“我的设置”,gameManager.walkSpeedTemp);
使用
new
关键字时,您正在创建
indicatorInfo
new实例。您保存了
indicatorInfo.walkSpeedTemfFile
来自该new实例,而没有为您创建的新
indicatorInfo
指定

可能您正试图做的是从编辑器中保存值

GameObject gameManagerObject = GameObject.FindGameObjectWithTag("GAMEMANAGER");
GAMEMANAGER gameManager = gameManagerObject.GetComponent<GAMEMANAGER>();
PlayerPrefs.SetFloat("my_setting", gameManager.walkSpeedTemp);
GameObject gameManagerObject=GameObject.FindGameObjectWithTag(“GAMEMANAGER”);
GAMEMANAGER GAMEMANAGER=gameManagerObject.GetComponent();
PlayerPrefs.SetFloat(“我的设置”,gameManager.walkSpeedTemp);