a15714ab041eb360be3335625683746f0153452ad6a6e889d63760f09e17cd6ed3c4b32d85adc0b1bb5c2626ced9


어떻게든 부채꼴 모양으로 카드 배열을 하려 하는데 마지막 5장이 일렬로 만들어지고,


a15714ab041eb360be3335625683746f0153452ad6a6e889d63760f0981ccd6ef428baf2f0140fea5aabad339b7e


그 이후 생성된 카드도 계속 가로로만 배치됨....


원하는 상태가 중점을 기준으로 계속 부채꼴로 늘어나가는 형식인데 안되네;;



코드를 안썼구나;; 수정

    public class CharacterDeckManager : MonoBehaviour

    {

        [Header("References")]

        public Transform deckParent; // 자기 자신을 할당

        public GameObject cardPrefab;


        public List<GameObject> cardsInHand = new List<GameObject>();


        void Start()

        {

            // 시작할 때 테스트 카드 5개 생성

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

            {

                GameObject newCard = Instantiate(cardPrefab, deckParent);

                cardsInHand.Add(newCard);

            }


            LayoutCards();

        }


        void LayoutCards()

        {

            Debug.Log("+ LayoutCards 실행됨! 카드 개수: " + cardsInHand.Count);


            int count = cardsInHand.Count;

            if (count == 0) return;


            // 카드 간격과 곡선 높이 증가 (더 둥글게 배치)

            float spacing = Mathf.Lerp(100f, 140f, 1f / (count * 0.3f + 1f));

            float fanAngle = 25f; // 회전 각도 증가

            float arcHeight = Mathf.Lerp(80f, 150f, count / 10f); // 높이 증가


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

            {

                float normalizedPos = count > 1 ? (i / (float)(count - 1) * 2 - 1) : 0;


                float xPos = normalizedPos * (spacing * count / 2);

                float yPos = -Mathf.Pow(normalizedPos, 2) * arcHeight;

                float angle = normalizedPos * fanAngle;


                RectTransform rt = cardsInHand[i].GetComponent<RectTransform>();

                rt.anchoredPosition = new Vector2(xPos, yPos);

                rt.localRotation = Quaternion.Euler(0, 0, angle);


                // 중앙 카드가 가장 앞쪽에 오도록 정렬

                int sortOrder = Mathf.RoundToInt((1 - Mathf.Abs(normalizedPos)) * count);

                cardsInHand[i].transform.SetSiblingIndex(count - sortOrder); // ⭐ 수정된 부분


                Debug.Log($"+ {i}번 카드 | X: {xPos}, Y: {yPos}, 회전: {angle}, 정렬순서: {count - sortOrder}");

            }

        }


        void Update()

        {

            // L 키를 눌러 수동으로 카드 정렬 실행 (테스트용)

            if (Input.GetKeyDown(KeyCode.L))

            {

                LayoutCards();

                Debug.Log("+ 수동으로 LayoutCards() 실행됨!");

            }

        }

    }

}