1. 실행 이미지

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class TabMenu : MonoBehaviour
{
    public Image tabFocus;
    public Image tabDefault;
    public bool isOn = true;

}

2. TabMenu.cs

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UITabMenu : MonoBehaviour
{
    [SerializeField] private Button[] buttons;
    // TabMenu 참조를 추가합니다.
    [SerializeField] private TabMenu[] tabMenu;

    void Start()
    {
        Init();


        for (int i = 0; i < buttons.Length; i++)
        {
            int idx = i;
            tabMenu[idx].isOn = false;

            buttons[idx].onClick.AddListener(() => {
                for(int j = 0; j < tabMenu.Length; j++)
                {
                    int idx2 = j;
                    tabMenu[idx2].tabFocus.gameObject.SetActive(false);
                    tabMenu[idx2].tabDefault.gameObject.SetActive(true);
                    tabMenu[idx2].isOn = false;
                }
                tabMenu[idx].tabFocus.gameObject.SetActive(true);
                tabMenu[idx].tabDefault.gameObject.SetActive(false);
                tabMenu[idx].isOn = true;
            });
        }
       


    }
    private void Init() // 첫번쨰 탭메뉴만 Focus 시작
    {
        for (int i = 0; i < buttons.Length; i++)
        {
            tabMenu[i].tabFocus.gameObject.SetActive(false);
            tabMenu[i].tabDefault.gameObject.SetActive(true);
            tabMenu[i].isOn = false;
        }

        tabMenu[0].tabFocus.gameObject.SetActive(true);
        tabMenu[0].tabDefault.gameObject.SetActive(false);
        tabMenu[0].isOn = true;
    }



}

3. UITabMenu.cs

+ Recent posts