C# enum형

m._.jooong·2023년 3월 2일
0

Unity C#

목록 보기
12/22
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

// enum 형
// 상수 숫자들을 보다 의미 있는 단어들로 표현하여 코드의 가독성을 높여 주는 문법  
public enum GawiBawiBo
{
    Gawi = 1,
    Bawi = 2,
    Bo = 3
}

public enum City
{
    Seoul,      //  0
    Inchenon,   //  1
    Busan = 5,  //  5
    Gwanghu,    //  6
    Jeju = 10,  //  10
    Shinchon,   //  11
    Count       //  12
}

public class Test_2 : MonoBehaviour
{
    [Header("--- Gameble ---")]
    public Button btn;

    // Start is called before the first frame update
    void Start()
    {
        City MyCity = City.Busan;
        Debug.Log("MyCity : " + MyCity+ " : Index("+(int)MyCity+")");
        Debug.Log("Shinchon : " + "Index(" + (int)City.Shinchon + ")");


        GawiBawiBo a_UserSel = GawiBawiBo.Gawi; //1이면 가위를 의미함
        GawiBawiBo a_ComSel = (GawiBawiBo)Random.Range(
                                (int)GawiBawiBo.Gawi, (int)GawiBawiBo.Bo + 1);  // 1 ~ 3 랜덤한 값 생성
        //1, 가위, 2, 바위, 3, 보

        //--- 판정
        if (a_UserSel == a_ComSel)
        {
            Debug.Log("비겼다.");
        }
        else if (a_UserSel == GawiBawiBo.Gawi && a_ComSel == GawiBawiBo.Bo)
        {
            Debug.Log("이겼다.");
        }
        else
        {
            Debug.Log("졌다.");
        }
        //--- 판정
    }

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

    }
}

0개의 댓글