【发布时间】:2017-09-20 21:05:39
【问题描述】:
正如我所提到的,我尝试在计算机上删除保存文件和运行游戏,它运行良好。但在 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;
}
}
【问题讨论】: