본문 바로가기
Unity/로또번호 추첨

[유니티] 로또번호 추첨하기

by Skull Crusher 2021. 4. 27.
728x90

1. C# Script

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LottoGame : MonoBehaviour
{
    //인스펙터에 생김
    //public int[] arrays;

    // Start is called before the first frame update
    void Start()
    {
        int[] lottoBalls = new int[6];

        string lottoStr = "";

        for (int i=0; i<lottoBalls.Length; i++)
        {
            lottoBalls[i] = Random.Range(1, 46);

            bool isSame = false;
            for (int j=0; j<i; j++)
            {
                if (lottoBalls[i] == lottoBalls[j])
                {
                    isSame = true;
                    i--;
                    break;
                }
            }

            if (isSame) continue;
            lottoStr += (lottoBalls[i].ToString() + ((i == lottoBalls.Length - 1) ? "" : ","));
        }

        Debug.Log(lottoStr);
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}

'Unity > 로또번호 추첨' 카테고리의 다른 글

[유니티] 로또번호 추첨하기(2)  (0) 2021.04.27

댓글