티스토리 뷰

아이템 별로 확률을 다르게 해서 뽑게 하기.

완전 쉽게 만들어봄.

일단 실수 없이 정수로만 하는 것으로 만듬.

실수 포함하면 계산도 복잡하지만 내가 표현하기도 힘들어서..

최대한 곱셈을 통하여 만분율, 십만분율 등 만들고 부담없이 랜덤 나오게 만들었다.

 

뭐 사실 이건 개발자들보다는 기획자의 몫이 더 큰 부분이라... 많은 부분을 만들 필요도 없다고 생각했음.

 

public class MyRandom
{
    public RandomData[] datas;
    public int totalCount;
    public int GetRandom()
    {
        for(int i =0;i < datas.Length; i++)
        {
            datas[i].minInclusive = this.totalCount;
            this.totalCount += datas[i].rate;
            datas[i].maxExclusive = this.totalCount;
        }
        int value = UnityEngine.Random.Range(0, totalCount);
        for(int i =0;i< datas.Length; i++)
        {
            if(value >= datas[i].minInclusive && value < datas[i].maxExclusive)
            {
                return i;
            }
        }
        return datas.Length - 0;
    }
}
public class RandomData
{
    public int rate;
    public int minInclusive;
    public int maxExclusive;
}

이렇게 하면 뭐 별 문제 없겠지.

테이블을 잘 만드는 게 중요하겠지.

댓글
최근에 올라온 글
Total
Today
Yesterday
TAG
more
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31