using UnityEngine;

using System.Collections.Generic;


public class PairGenerator : MonoBehaviour

{

    void Start()

    {

        // 그룹 A, B, C에 숫자 할당

        List<int> groupA = new List<int>() { 1, 2, 3, 4, 5, 6 };

        List<int> groupB = new List<int>() { 7, 8, 9, 10, 11, 12, 13 };

        List<int> groupC = new List<int>() { 14, 15, 16, 17, 18, 19, 20 };


        // 숫자 쌍을 저장할 리스트

        List<List<int>> pairs = new List<List<int>>();


        // 겹치는 그룹이 없는 10개의 숫자 쌍을 무작위로 뽑기

        for (int i = 0; i < 10; i++)

        {

            List<int> selectedPair = new List<int>();


            // 각 그룹에서 숫자를 무작위로 선택

            List<int> availableGroups = new List<int> { 0, 1, 2 }; // A: 0, B: 1, C: 2

            while (selectedPair.Count < 2 && availableGroups.Count > 0)

            {

                int randomGroupIndex = Random.Range(0, availableGroups.Count);

                int groupIndex = availableGroups[randomGroupIndex];

                List<int> selectedGroup = GetGroupByIndex(groupIndex, groupA, groupB, groupC);


                if (selectedGroup.Count > 0)

                {

                    int randomIndex = Random.Range(0, selectedGroup.Count);

                    selectedPair.Add(selectedGroup[randomIndex]);

                    selectedGroup.RemoveAt(randomIndex);

                    availableGroups.Remove(groupIndex);

                }

            }


            if (selectedPair.Count == 2)

            {

                pairs.Add(selectedPair);

            }

        }


        // 결과 출력

        foreach (List<int> pair in pairs)

        {

            Debug.Log(pair[0] + " " + pair[1]);

        }

    }


    // 인덱스에 따라 그룹을 반환

    List<int> GetGroupByIndex(int index, List<int> groupA, List<int> groupB, List<int> groupC)

    {

        switch (index)

        {

            case 0:

                return groupA;

            case 1:

                return groupB;

            case 2:

                return groupC;

            default:

                return new List<int>();

        }

    }

}

이거 실행하면 유니티 멈춰버림 ㅅㅂ 왜 멈추는거지????????????????????????????

버전은 2021.3.20f1