IdleGirl/Assets/2_Codes/RandomSelect.cs

49 lines
1.1 KiB
C#

using System.Collections.Generic;
using UnityEngine;
public class RandomSelect : MonoBehaviour
{
public List<Card> deck = new List<Card>();
public int total = 0;
public List<int> result = new List<int>();
public void ResultSelect()
{
int randomIndex = RandomCard();
result[randomIndex]++;
}
private int RandomCard()
{
int weight = 0;
int selectNum = Mathf.RoundToInt(total * Random.Range(0.0f, 1.0f));
for (int i = 0; i < deck.Count; i++)
{
weight += deck[i].weight;
if (selectNum <= weight)
{
return i;
}
}
return 0;
}
private void Start()
{
for (int i = 0; i < deck.Count; i++)
{
total += deck[i].weight;
result.Add(0); // 결과 리스트 초기화
}
for (int i = 0; i < 10000; i++)
{
ResultSelect(); // 카드 선택 및 결과 업데이트
}
for (int i = 0; i < result.Count; i++)
{
Debug.Log(result[i]);
}
}
}