
Switch 문
Tutorial
Beginner
+10XP
5 mins
(45)
Unity Technologies

Switch 문은 조건문을 간소화한 형태로, 하나의 변수를 여러 상수와 비교하려는 경우에 유용합니다. 이 영상에서는 switch 문을 작성하고 사용하는 방법을 알아봅니다.
이 튜토리얼은 스크립팅의 기초 프로젝트에 포함되어 있습니다.
이전: 열거형
다음: 이 강좌가 프로젝트의 마지막 튜토리얼입니다.
1. Switch 문
ConversationScript
using UnityEngine;
using System.Collections;
public class ConversationScript : MonoBehaviour
{
public int intelligence = 5;
void Greet()
{
switch (intelligence)
{
case 5:
print ("Why hello there good sir! Let me teach you about Trigonometry!");
break;
case 4:
print ("Hello and good day!");
break;
case 3:
print ("Whadya want?");
break;
case 2:
print ("Grog SMASH!");
break;
case 1:
print ("Ulg, glib, Pblblblblb");
break;
default:
print ("Incorrect intelligence level.");
break;
}
}
}