1. 실행 이미지

 

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

public class RewardMenu : MonoBehaviour
{
    [SerializeField] Button[] rewardBtns;
    [SerializeField] Reward[] rewardScripts;

    [SerializeField] Button claimBtn;

    private void Start()
    {
        Init();

        for(int i=0; i<rewardBtns.Length; i++)
        {
            int idx = i;
            rewardBtns[idx].onClick.AddListener(() => {
                for(int j = 0; j<rewardBtns.Length; j++)
                {
                    int idx2 = j;
                    rewardScripts[idx2].focus.gameObject.SetActive(false);
                }
                rewardScripts[idx].focus.gameObject.SetActive(true);
            });
        }



        claimBtn.onClick.AddListener(() => {
            for(int i = 0; i< rewardScripts.Length; i++)
            {
                int idx3 = i;
                rewardScripts[idx3].text.gameObject.SetActive(true);
            }
        });
    }

    private void Init()
    {
        for(int i = 0; i < rewardScripts.Length; i++)
        {
            rewardScripts[i].focus.gameObject.SetActive(false);
            rewardScripts[i].text.gameObject.SetActive(false);
        }
    }


}

2. RewardMenu.cs

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

public class Reward : MonoBehaviour
{
    public Image focus;
    public TMP_Text text;
}

3. Reward.cs

+ Recent posts