_TheStrongestSnail/TheStrongestSnail/Assets/Scripts/RacingPanel/RacingPanel.cs
2024-11-27 22:24:11 +08:00

144 lines
3.1 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;
// Start is called before the first frame update
void Start()
{
//美队
btnMei.onClick.AddListener(() =>
{
//更新按钮图片上滑
ImgUpward(imgMei, imgMeiQ);
//当前选中的蜗牛
});
//蜘蛛侠
btnPig.onClick.AddListener(() =>
{
ImgUpward(imgPig, imgPigQ);
});
//毒液
btnDu.onClick.AddListener(() =>
{
ImgUpward(imgDu, imgDuQ);
});
//钢铁侠
btnGang.onClick.AddListener(() =>
{
ImgUpward(imgGang, imgGangQ);
});
//蝙蝠侠
btnBian.onClick.AddListener(() =>
{
ImgUpward(imgBian, imgBianQ);
});
//超人
btnChao.onClick.AddListener(() =>
{
ImgUpward(imgChao, imgChaoQ);
});
//雷神
btnLei.onClick.AddListener(() =>
{
ImgUpward(imgLei, imgLeiQ);
});
//灭霸
btnMie.onClick.AddListener(() =>
{
ImgUpward(imgMie, imgMieQ);
});
}
// 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;
}
}