Files
PuzzleColorBall/Assets/Scripts/CoinCounter.cs

59 lines
1.6 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-17 10:46:50 +01:00
public ulong coin = ulong.MaxValue; //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-17 10:46:50 +01:00
private DatabaseData db;
2023-03-14 16:45:09 +01:00
private void Awake() {
2023-03-17 10:46:50 +01:00
db = FindObjectOfType<DatabaseData>();
/*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();
2023-03-17 10:46:50 +01:00
Debug.Log("Coins at start: " + coin);*/
2023-03-14 16:45:09 +01:00
2023-03-17 10:46:50 +01:00
/*Debug.Log("coin 1: " + coin);
coin = db.GetCoins(1);
Debug.Log("itt van coin");
Debug.Log("coin 2: " + coin);
coinCounterUI.text = "Coins: " + coin.ToString();*/
2023-03-07 21:06:25 +01:00
}
2023-03-17 10:46:50 +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
2023-03-20 19:56:27 +01:00
/*writer = new StreamWriter(path, false, Encoding.Default);
2023-03-14 16:45:09 +01:00
writer.Write(coin);
2023-03-20 19:56:27 +01:00
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
2023-03-20 19:56:27 +01:00
/*writer = new StreamWriter(path, false, Encoding.Default);
2023-03-14 16:45:09 +01:00
writer.Write(coin);
2023-03-20 19:56:27 +01:00
writer.Close();*/
2023-02-27 12:09:47 +01:00
}
}