前回、"if(){ } else if(){ }"の説明で下のような例を出しました


if( a == 1 ){
Debug.Log("aは1");
} else if( a == 2 ){
Debug.Log("aは2");
} else if( a == 3 ){
Debug.Log("aは3");
} else {
Debug.Log("aは1でも2でも3でもない");
}

"switch文"を使用するとこれを下のように書けます。
実行結果はif文でもswitch文でも両方同じです。


switch( a ){
case 1:
 Debug.Log("aは1");
 break;
case 2:
 Debug.Log("aは2");
 break;
case 3:
 Debug.Log("aは3");
 break;
default:
 Debug.Log("aは1でも2でも3でもない");
 break;
}