e4f8167dd7
bank
78 lines
1.8 KiB
C#
78 lines
1.8 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class BankUIManager : MonoBehaviour
|
|
{
|
|
public GameObject bankUIPanel; // Panel interfejsu bankowego
|
|
public Button submitButton; // Przycisk do zatwierdzania
|
|
public Button close;
|
|
public InputField amountInputField; // Pole do wprowadzania kwoty
|
|
public Text kasa;
|
|
private float money;
|
|
public Text blad;
|
|
public GameObject cubes;
|
|
|
|
void Start()
|
|
{
|
|
// Ukryj panel bankowy na pocz¹tku
|
|
bankUIPanel.SetActive(false);
|
|
|
|
// Dodaj nas³uchiwanie klikniêæ do przycisków
|
|
|
|
submitButton.onClick.AddListener(bank_work);
|
|
close.onClick.AddListener(CloseBankUI);
|
|
|
|
|
|
|
|
|
|
// Ustaw referencje do komponentów UI
|
|
|
|
}
|
|
|
|
void OnTriggerEnter(Collider other)
|
|
{
|
|
if (gameObject.CompareTag("cubess"))
|
|
{
|
|
OpenBankUI(); // Otwórz panel bankowy przy kolizji z obiektem o tagu "cubess"
|
|
}
|
|
}
|
|
|
|
public void OpenBankUI()
|
|
{
|
|
bankUIPanel.SetActive(true);
|
|
}
|
|
|
|
public void CloseBankUI()
|
|
{
|
|
bankUIPanel.SetActive(false);
|
|
}
|
|
|
|
private void bank_work()
|
|
{
|
|
blad = GameObject.Find("blad").GetComponent<Text>();
|
|
string amountText = amountInputField.text;
|
|
float amount;
|
|
|
|
// SprawdŸ, czy wpisana wartoœæ jest liczb¹
|
|
if (float.TryParse(amountText, out amount))
|
|
{
|
|
money += amount;
|
|
kasa.text = "money: " + money + "$";
|
|
Color color = blad.color;
|
|
color.a = 0;
|
|
blad.color = color;
|
|
}
|
|
else
|
|
{
|
|
Color color = blad.color;
|
|
color.a = 1;
|
|
blad.color= color;
|
|
blad.text = "Podaj prawid³ow¹ kwotê";
|
|
}
|
|
|
|
}
|
|
|
|
|
|
} |