본문 바로가기
개발/C#

유니티 C# 특정 값을 제외한 랜덤 값 구하기 Unity Random Value Generator

by SPNK 2023. 3. 19.
반응형
  • 코드 작성
using UnityEngine;
using System.Collections.Generic;

public class RandomNumberGenerator : MonoBehaviour
{
    private List<int> exclusionList = new List<int>() { 2, 3, 5, 6 }; //제외할 값
    
    private int GenerateRandomNumber(int min, int max)
    {
        int randomValue = Random.Range(min, max);
        while (exclusionList.Contains(randomValue))
        {
            randomValue = Random.Range(min, max);
        }
        return randomValue;
    }
}
반응형

댓글