Files
PuzzleColorBall/Assets/Scripts/CoinCounter.cs

51 lines
1.4 KiB
C#
Raw Normal View History

2023-02-27 12:09:47 +01:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2023-03-09 14:07:44 +01:00
using TMPro;
2023-03-14 16:45:09 +01:00
using System.IO;
using System.Text;
2023-02-27 12:09:47 +01:00
public class CoinCounter : MonoBehaviour
{
2023-03-14 16:45:09 +01:00
public ulong coin; //szedje le db-bol a playerhez a coint
2023-03-09 14:07:44 +01:00
public TMP_Text coinCounterUI;
2023-03-14 16:45:09 +01:00
private string path;
private StreamWriter writer;
private StreamReader reader;
2023-02-27 12:09:47 +01:00
2023-03-14 16:45:09 +01:00
private void Awake() {
path = Application.persistentDataPath + "/coins.txt";
2023-03-07 21:06:25 +01:00
2023-03-14 16:45:09 +01:00
if(!File.Exists(path)){ //ha nincs meg ilyen fajl hozza letre
writer = new StreamWriter(path, false, Encoding.Default);
writer.Write(0);
writer.Close();
}
2023-03-07 21:06:25 +01:00
2023-03-14 16:45:09 +01:00
reader = new StreamReader(path);
coin = ulong.Parse(reader.ReadLine());
reader.Close();
Debug.Log("Coins at start: " + coin);
coinCounterUI.text = "Coins: " + coin.ToString();
2023-03-07 21:06:25 +01:00
}
2023-02-27 12:09:47 +01:00
public void AddCoin(ulong number){
coin += number;
2023-03-09 16:00:42 +01:00
coinCounterUI.text = "Coins: " + coin.ToString();
2023-03-14 16:45:09 +01:00
writer = new StreamWriter(path, false, Encoding.Default);
writer.Write(coin);
writer.Close();
2023-02-27 12:09:47 +01:00
}
public void RemoveCoin(ulong number){
coin -= number;
2023-03-09 16:00:42 +01:00
//coinCounterUI.text = "Coins: " + coin.ToString();
2023-03-14 16:45:09 +01:00
writer = new StreamWriter(path, false, Encoding.Default);
writer.Write(coin);
writer.Close();
2023-02-27 12:09:47 +01:00
}
}