Files

67 lines
1.8 KiB
C#
Raw Permalink 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-05-02 13:46:38 +02: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-17 10:46:50 +01:00
private DatabaseData db;
2023-05-02 13:46:38 +02:00
private UsernameHandler usernameHandler;
2023-03-17 10:46:50 +01:00
2023-03-14 16:45:09 +01:00
private void Awake() {
2023-03-17 10:46:50 +01:00
db = FindObjectOfType<DatabaseData>();
2023-05-02 13:46:38 +02:00
usernameHandler = FindObjectOfType<UsernameHandler>();
2023-03-17 10:46:50 +01:00
/*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-05-02 13:46:38 +02:00
public void SetCoin(ulong number){
coin = number;
2023-05-30 09:09:24 +02:00
coinCounterUI.text = coin.ToString();
2023-05-02 13:46:38 +02: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-05-30 09:09:24 +02:00
coinCounterUI.text = 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-05-30 09:09:24 +02:00
coinCounterUI.text = 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
}
}