111 lines
3.0 KiB
C#
111 lines
3.0 KiB
C#
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;//投注的值
|
||
|
||
public Button BetButton;//投注的按钮
|
||
|
||
public GameObject text1;
|
||
public GameObject text2;
|
||
public GameObject text3;
|
||
public GameObject text4;
|
||
public GameObject text5;
|
||
public GameObject text6;
|
||
// Start is called before the first frame update
|
||
void Start()
|
||
{
|
||
BetList.SetActive(false);
|
||
NumBtn.onClick.AddListener(OnClickNumBtn);
|
||
BetButton.onClick.AddListener(OnClickBetBtn);
|
||
BetValue = 50;//默认50
|
||
SetBet();
|
||
}
|
||
|
||
void OnClickNumBtn()
|
||
{
|
||
BetList.SetActive(true);
|
||
|
||
}
|
||
|
||
void OnClickBetBtn()
|
||
{
|
||
if (HegemonTime.instance.timeNum>20)
|
||
{
|
||
switch (PlayerMovePos.instance.HouseId)
|
||
{
|
||
case 1:
|
||
if (PlayerInfo.instance.SetMoney(-BetValue))
|
||
{
|
||
text1.GetComponent<TextBox>().SetText(BetValue);
|
||
}
|
||
break;
|
||
case 2:
|
||
if (PlayerInfo.instance.SetMoney(-BetValue))
|
||
{
|
||
text2.GetComponent<TextBox>().SetText(BetValue);
|
||
}
|
||
break;
|
||
case 3:
|
||
if (PlayerInfo.instance.SetMoney(-BetValue))
|
||
{
|
||
text3.GetComponent<TextBox>().SetText(BetValue);
|
||
}
|
||
break;
|
||
case 4:
|
||
if (PlayerInfo.instance.SetMoney(-BetValue))
|
||
{
|
||
text4.GetComponent<TextBox>().SetText(BetValue);
|
||
}
|
||
break;
|
||
case 5:
|
||
if (PlayerInfo.instance.SetMoney(-BetValue))
|
||
{
|
||
text5.GetComponent<TextBox>().SetText(BetValue);
|
||
}
|
||
break;
|
||
case 6:
|
||
if (PlayerInfo.instance.SetMoney(-BetValue))
|
||
{
|
||
text6.GetComponent<TextBox>().SetText(BetValue);
|
||
}
|
||
break;
|
||
default:
|
||
Debug.Log("请选择房间");
|
||
break;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
Debug.Log("现在无法投注");
|
||
}
|
||
|
||
|
||
}
|
||
|
||
|
||
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);
|
||
});
|
||
}
|
||
}
|
||
|
||
|
||
}
|