Files
ConvenientHorror/Assets/Scripts/Button Functions/ShopScript.cs

153 lines
3.0 KiB
C#

using System.Xml.Serialization;
using TMPro;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.U2D;
public class ShopScript : MonoBehaviour
{
[SerializeField] GameObject shopPanel;
[SerializeField] GameObject errorPanel;
private bool paymentSystemActive = false;
//TMP_Text textfeld;
[SerializeField] TMP_Text textfeld;
InventoryScript inventory;
private float moneten = 1000; //als vorerstiger Ersatz für tatsächliches Geld
private int gemsCost = 100; //1€
private int manyGemsCost = 200; //2€
private int updateCost = 100;
#region DevMode
[SerializeField] GameObject devPanel;
//TMP_Text textfeldA; //als textfeld
//TMP_Text textfeldB;
//TMP_Text textfeldC;
[SerializeField] TMP_Text textfeldA; //als text
[SerializeField] TMP_Text textfeldB;
[SerializeField] TMP_Text textfeldC;
#endregion
void Start()
{
InventoryScript inventory = GetComponent<InventoryScript>();
shopPanel.SetActive(false);
errorPanel.SetActive(false);
devPanel.SetActive(false);
//textfeld = this.text;
}
void Update()
{
textfeld.text = inventory.Gems.ToString();
ShowDevMode();
}
public void OpenShop()
{
shopPanel.SetActive(true);
}
public void CloseShop()
{
shopPanel.SetActive(false);
}
public void ClosePanel()
{
errorPanel.SetActive(false);
}
public void AddLife()
{
inventory.Health++;
inventory.Gems -= updateCost;
}
public void AddEnergy()
{
inventory.Energy++;
inventory.Gems -= updateCost;
}
public void BuyGems()
{
if (paymentSystemActive)
{
moneten -= gemsCost;
Debug.Log("Ich mag Moeneten");
}
else
{
errorPanel.SetActive(true);
}
}
public void BuyMore()
{
if (paymentSystemActive)
{
moneten -= manyGemsCost;
Debug.Log("Ich mag Moeneten");
}
else
{
errorPanel.SetActive(true);
}
}
public void ShowDevMode()
{
devPanel.SetActive(true);
//textfeldA = textA;
//textfeldB = textB;
//textfeldC = textC;
textfeldA.text = inventory.Energy.ToString();
textfeldB.text = inventory.Health.ToString();
textfeldC.text = moneten.ToString();
}
public void ChangeActivation()
{
SpriteRenderer spriteRenderer = GetComponent<SpriteRenderer>();
if (paymentSystemActive)
{
paymentSystemActive = false;
spriteRenderer.sprite = Resources.Load<Sprite>("T_11_no.png");
}
else
{
paymentSystemActive = true;
spriteRenderer.sprite = Resources.Load<Sprite>("T_12_ok.png");
}
}
public void CloseDevPanel()
{
devPanel.SetActive(false);
}
}