본문 바로가기
카테고리 없음

[코딩일기] C# enum

by mania2321 2024. 7. 17.

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

public class Helloworld_2 : MonoBehaviour
{
    // enum 열거

    enum ProjectileKind         // 열거
    {
        Arrow,
        Bullet,
        Missile
    }

    

    void Start()
    {
        ProjectileKind kind;

        kind = ProjectileKind.Arrow;        // 투사체의 종류는 화살이라는 뜻
        
        switch(kind)
        {
            case ProjectileKind.Arrow:
                Debug.Log("화살 입니다.");
                break;

            case ProjectileKind.Bullet:
                Debug.Log("총알 입니다.");
                break;

            case ProjectileKind.Missile:
                Debug.Log("미사일 입니다");
                break;
        }
    }
}

댓글