_TheStrongestSnail/TheStrongestSnail/Assets/Scripts/Battle_Royale/BettingBtn.cs
2024-11-12 14:06:34 +08:00

45 lines
1.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class BettingBtn : MonoBehaviour
{
public GameObject BetList;
public Button NumBtn;
public Text BetText;
public float BetValue;//投注的值
// Start is called before the first frame update
void Start()
{
BetList.SetActive(false);
NumBtn.onClick.AddListener(OnClickNumBtn);
BetValue = 50;//默认50
SetBet();
}
void OnClickNumBtn()
{
BetList.SetActive(true);
}
void SetBet()
{
// 获取所有的Button组件
Button[] buttons = BetList.GetComponentsInChildren<Button>();
// 遍历每一个Button添加点击事件
foreach (Button button in buttons)
{
button.onClick.AddListener(() => {
BetText.text = button.transform.GetComponentInChildren<Text>().text;
BetValue = float.Parse(BetText.text);
BetList.SetActive(false);
});
}
}
}