Created
August 23, 2012 16:08
-
-
Save nakamura001/3438115 to your computer and use it in GitHub Desktop.
[Unity]ファイルにアプリの起動回数を保存
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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