忘了是学unity的多少天了,已经混淆时间了
今天在做用户面板的时候希望通过点击向左和向右来切换图标的选中。代码是这样的:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace GreatDay
{
public class UPanel : MonoBehaviour
{
public GameObject upanel;
public GameObject upanel1;
public GameObject upanel2;
public GameObject upanel3;
private bool isShow;
private int currentPanel = 3; // 假设初始时显示的是panel1
//管理button组件
public List<Button> buttons; // 存储所有按钮的列表
public Color selectedColor; // 选中时的颜色
public Color unselectedColor; // 未选中时的颜色
private int currentSelectedIndex = 0; // 当前选中的按钮索引
// Start is called before the first frame update
void Start()
{
isShow = false;
SetButtonColor(buttons[currentSelectedIndex], selectedColo