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<63>tku
|
|||
|
bankUIPanel.SetActive(false);
|
|||
|
|
|||
|
// Dodaj nas<61>uchiwanie klikni<6E><69> do przycisk<73>w
|
|||
|
|
|||
|
submitButton.onClick.AddListener(bank_work);
|
|||
|
close.onClick.AddListener(CloseBankUI);
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
// Ustaw referencje do komponent<6E>w UI
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
void OnTriggerEnter(Collider other)
|
|||
|
{
|
|||
|
if (gameObject.CompareTag("cubess"))
|
|||
|
{
|
|||
|
OpenBankUI(); // Otw<74>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<77>, czy wpisana warto<74><6F> jest liczb<7A>
|
|||
|
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<69>ow<6F> kwot<6F>";
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|