반응형
Enum 이란?
상수에 이름을 붙여 구분을 쉽게 하기위해 사용합니다.
- Enum을 사용하지 않고 코드 작성시
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ExampleEnum : MonoBehaviour
{
int gold = 0;
int crystal = 1;
int money = 0;
void Awake()
{
money = 0;
switch (money)
{
case 0:
Debug.Log("골드 발견");
break;
case 1:
Debug.Log("크리스탈 발견");
break;
default:
Debug.Log("아무것도 발견하지 못했습니다");
break;
}
}
}
- Enum을 사용해서 코드 작성시
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum MoneyType
{
Gold = 0,
Crystal
}
public class ExampleEnum : MonoBehaviour
{
public MoneyType moneyType = MoneyType.Gold;
void Awake()
{
moneyType = MoneyType.Gold;
switch (moneyType)
{
case MoneyType.Gold:
Debug.Log("골드 발견");
break;
case MoneyType.Crystal:
Debug.Log("크리스탈 발견");
break;
default:
Debug.Log("아무것도 발견하지 못했습니다");
break;
}
int number = (int)moneyType; //결과 : 0
}
}
참고할만한 글
반응형
'개발 > C#' 카테고리의 다른 글
유니티 C# 파일 저장 경로 System Path 간단 사용법 (0) | 2022.06.19 |
---|---|
유니티 C# DontDestroyOnLoad 간단 사용법 (0) | 2022.06.19 |
유니티 C# 구글 로그인 Google Play Games GPGS 간단 구현 (0) | 2022.06.19 |
유니티 C# 싱글톤 패턴 Singleton Pattern 간단 사용법 (0) | 2022.06.19 |
유니티 C# 구글 애드몹 보상형 광고 간단 구현 Google Admob 8.7.0 (0) | 2022.06.19 |
유니티 C# 형 변환 Type Conversions 간단 사용법 (0) | 2022.06.19 |
유니티 C# 최적화 기법 Object Pooling 오브젝트 풀링 간단 사용법 (0) | 2022.06.15 |
유니티 C# Scriptable Object 스크립터블 오브젝트 간단 사용법 (0) | 2022.06.15 |
댓글