Skip to content

Instantly share code, notes, and snippets.

@nakamura001
Created August 23, 2012 16:08
Show Gist options
  • Save nakamura001/3438115 to your computer and use it in GitHub Desktop.
Save nakamura001/3438115 to your computer and use it in GitHub Desktop.
[Unity]ファイルにアプリの起動回数を保存
using System.IO;
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
private string path;
private string counter;
void Start ()
{
path = Application.persistentDataPath + @"/test.txt";
if (!File.Exists (path)) {
counter = "1";
} else {
string txt = File.ReadAllText (path);
counter = (int.Parse (txt) + 1).ToString();
}
File.WriteAllText (path, counter);
}
void OnGUI () {
GUI.TextArea(new Rect(5, 5, Screen.width, 50), counter + ":"+ path);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment