正如我所提到的,我尝试删除保存文件并在计算机上整理游戏,它完美无缺。但是在Android上,它既不会创建文件,也不会创建文件,但不会在其中写入任何内容。
以下是SaveFileManagement
的代码:
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.UI;
public class onAppStart : MonoBehaviour {
public Text moneyText;
void Start () {
if (!File.Exists("doubleMoney.txt"))
{
File.Create("doubleMoney").Dispose();
System.IO.File.WriteAllText("doubleMoney.txt", "0");
}
if (!File.Exists("money.txt"))
{
File.Create("money").Dispose();
System.IO.File.WriteAllText("money.txt", "2.5");
double doubleMoney = Convert.ToDouble(System.IO.File.ReadAllText("money.txt"));
float money = ToSingle(doubleMoney);
moneyText.text = money.ToString() + "$";
}
else
{
double doubleMoney = Convert.ToDouble(System.IO.File.ReadAllText("money.txt"));
float money = ToSingle(doubleMoney);
moneyText.text = money.ToString() + "$";
}
}
public static float ToSingle(double value)
{
return (float)value;
}
}
答案 0 :(得分:0)
您正在尝试创建" doubleMoney",但写入/检查" doubleMoney.txt"的存在。修复您的文件名以保持一致。