2024-12-04 17:26:27 +08:00

61 lines
1.3 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.UI;
public class BuyButton : MonoBehaviour
{
[SerializeField] private int id;
[SerializeField] private int needGold;
[SerializeField] private Image icon;
[SerializeField] private Button _button;
[SerializeField] private TextMeshProUGUI text;
private void Awake()
{
_button = GetComponent<Button>();
text.text = needGold.ToString();
}
private void OnEnable()
{
_button.onClick.AddListener(ButtonEvent);
}
// Start is called before the first frame update
void Start()
{
icon.sprite = GameSystem.ins.DataAsset.IconSprite(id);
}
// Update is called once per frame
void Update()
{
}
private void OnDisable()
{
_button.onClick.RemoveListener(ButtonEvent);
}
void ButtonEvent()
{
if (GameSystem.ins.goldCoin>needGold)
{
DataManager.AddItem(id,1);
GameSystem.ins.goldCoin -= needGold;
GameSystem.ins.ResetItem();
GameSystem.ins.forgePanel.ResetGold();
}
else
{
GameSystem.ins.forgePanel._buyEventButton.gameObject.SetActive(true);
}
}
}