2024-11-21 10:26:47 +08:00
|
|
|
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)
|
|
|
|
{
|
2024-12-04 17:26:27 +08:00
|
|
|
DataManager.AddItem(id,1);
|
2024-11-21 10:26:47 +08:00
|
|
|
GameSystem.ins.goldCoin -= needGold;
|
|
|
|
GameSystem.ins.ResetItem();
|
|
|
|
GameSystem.ins.forgePanel.ResetGold();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GameSystem.ins.forgePanel._buyEventButton.gameObject.SetActive(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|