Код
using UnityEngine;
using System.Collections;
using System;
using System.IO; // Используем библиотеку ввода вывода
public class Menu : MonoBehaviour {
public int status = 1;
public GUIStyle style;
private Rect[] rect = new Rect[10];
public Texture2D[] language = new Texture2D[10];
public string[] languageS = new string[10];
private bool set = false;
private float crx;
private float cry;
private float cmx;
private float cmy;
private Texture2D transformI;
private string transformIS;
public Texture2D TransformI;
public string TransformIS;
public string[] text = new string[10];
private string filename = "settings.ini";
private int n;
private GameObject Global;
private Var Var;
private int x;
// Use this for initialization
void Start () {
Global = GameObject.Find("Global");
Var = Global.GetComponent<Var>();
if(!File.Exists(filename)){
text[0] = languageS[0];
File.WriteAllLines(filename, text);
}
else{
text = File.ReadAllLines(filename);
}
if(text[0] != languageS[0]){
x = 0;
do
{
x++;
if(text[0] == languageS[x]){
TransformI = language[0];
TransformIS = languageS[0];
language[0] = language[x];
languageS[0] = languageS[x];
language[x] = TransformI;
languageS[x] = TransformIS;
break;
}
}while (text[0] != languageS[x]);
}
crx = Screen.width * 0.90f;
cry = Screen.height * 0.90f;
cmx = Screen.width * 0.05f;
cmy = cmx * 0.66f;
rect[0] = new Rect(Screen.width * 0.05f,Screen.height * 0.68f, 300, 300);
rect[1] = new Rect(Screen.width * 0.05f,Screen.height * 0.68f + (Screen.width * 0.035f), 300, 300);
rect[2] = new Rect(Screen.width * 0.05f,Screen.height * 0.88f, 300, 300);
rect[3] = new Rect( crx, cry, cmx, cmy);
rect[4] = new Rect( crx, cry - cmy - 2, cmx, cmy);
rect[5] = new Rect( crx, cry - 2 * cmy - 4, cmx, cmy);
style.fontSize = (int)(Screen.width * 0.03f);
}
// Update is called once per frame
void Update () {
}
void Flag(int z){
set = false;
transformI = language[z];
transformIS = languageS[z];
language[z] = language[0];
languageS[z] = languageS[0];
language[0] = transformI;
languageS[0] = transformIS;
text = File.ReadAllLines(filename);
text[0] = transformIS;
Var.language = text[0];
File.WriteAllLines(filename, text);
}
void OnGUI () {
if(GUI.Button (rect[0], Var.Play, style)){
Application.LoadLevel(1);
}
if(GUI.Button (rect[1], Var.Options, style)){
}
if(GUI.Button (rect[2], Var.Exit, style)){
}
if(GUI.Button (rect[3], language[0], style)){
set = true;
}
if(set){
if(GUI.Button (rect[4],language[1], style)){
Flag(1);
}
if(GUI.Button (rect[5],language[2], style)){
Flag(2);
}
}
}
}
Добавлено (20.10.2014, 19:34)
---------------------------------------------
Цитата Snake174 (
)
Проверь ещё что StreamWriter и StreamReader закрываешь перед тем как вызывать WriteAllLines и ReadAllLines.
Я не знал,, что это надо делать