_TheStrongestSnail/TheStrongestSnail/Assets/Scripts/RacingPanel/RacingPanel.cs
2024-11-27 23:40:28 +08:00

170 lines
3.9 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class RacingPanel : MonoBehaviour
{
//帮助
public Button btnHelp;
//投入蜗蛋
public Button btnPut;
//冠军记录
public Button btnFirst;
//任务
public Button btnTask;
//关闭
public Button btnClose;
//美队
public Button btnMei;
//蜘蛛侠
public Button btnPig;
//毒液
public Button btnDu;
//钢铁侠
public Button btnGang;
//蝙蝠侠
public Button btnBian;
//超人
public Button btnChao;
//雷神
public Button btnLei;
//灭霸
public Button btnMie;
public RectTransform imgMei;
public RectTransform imgPig;
public RectTransform imgDu;
public RectTransform imgGang;
public RectTransform imgBian;
public RectTransform imgChao;
public RectTransform imgLei;
public RectTransform imgMie;
//当前选中的图片位置
private RectTransform nowImg;
public GameObject imgMeiQ;
public GameObject imgPigQ;
public GameObject imgDuQ;
public GameObject imgGangQ;
public GameObject imgBianQ;
public GameObject imgChaoQ;
public GameObject imgLeiQ;
public GameObject imgMieQ;
//当前选中蜗牛的钱
private GameObject nowObj;
//蜗牛卡上我投的钱
public Text imgMeiT;
public Text imgPigT;
public Text imgDuT;
public Text imgGangT;
public Text imgBianT;
public Text imgChaoT;
public Text imgLeiT;
public Text imgMieT;
public Text AllimgMeiT;
public Text AllimgPigT;
public Text AllimgDuT;
public Text AllimgGangT;
public Text AllimgBianT;
public Text AllimgChaoT;
public Text AllimgLeiT;
public Text AllimgMieT;
// Start is called before the first frame update
void Start()
{
//美队
btnMei.onClick.AddListener(() =>
{
//更新按钮图片上滑
ImgUpward(imgMei, imgMeiQ);
//当前选中的蜗牛
BetBtn.instance.BetHorseId = 1;
});
//蜘蛛侠
btnPig.onClick.AddListener(() =>
{
ImgUpward(imgPig, imgPigQ);
BetBtn.instance.BetHorseId = 2;
});
//毒液
btnDu.onClick.AddListener(() =>
{
ImgUpward(imgDu, imgDuQ);
BetBtn.instance.BetHorseId = 3;
});
//钢铁侠
btnGang.onClick.AddListener(() =>
{
ImgUpward(imgGang, imgGangQ);
BetBtn.instance.BetHorseId = 4;
});
//蝙蝠侠
btnBian.onClick.AddListener(() =>
{
ImgUpward(imgBian, imgBianQ);
BetBtn.instance.BetHorseId = 5;
});
//超人
btnChao.onClick.AddListener(() =>
{
ImgUpward(imgChao, imgChaoQ);
BetBtn.instance.BetHorseId = 6;
});
//雷神
btnLei.onClick.AddListener(() =>
{
ImgUpward(imgLei, imgLeiQ);
BetBtn.instance.BetHorseId = 7;
});
//灭霸
btnMie.onClick.AddListener(() =>
{
ImgUpward(imgMie, imgMieQ);
BetBtn.instance.BetHorseId = 8;
});
}
// Update is called once per frame
void Update()
{
}
private void ImgUpward(RectTransform rec,GameObject obj)
{
//首先判断当前图片是否为空 不为空才处理
if (nowImg!=null)
{
nowImg.localPosition = Vector3.zero;
}
//判断当前选中的游戏对象是否为空 不为空才处理
if (nowObj!=null)
{
nowObj.SetActive(false);
}
//判断是否点击的是同一个按钮
if (nowObj == obj && nowImg == rec)
{
nowImg = null;
nowObj = null;
return;
}
rec.localPosition = new Vector3(0,50,0);
obj.SetActive(true);
//重新赋值
nowImg=rec;
nowObj=obj;
}
}