how to write switch statement unity Code Answer
A switch statement permits an unsettled statement to be checked for justice in opposite to table of values.Every value is often known as case,while the statement that is being changed is examined in case of every switch case.A switch statement can have some rules and regulations which are given below, A switch statement can be systematic,that could be shown at the end of the switch.When none of the other case in true then default case runs. Each situation does not have any rest,if the rest persists then it would show compile time error. In case the break statement approaches,the switch is switched off,after that the running of command goes to the following line.
how to write switch statement unity
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;
}
}
}
Switch statement may perform the similar measures for the different situations,equal to that situations when we have numerous circumstances in just one statement.This case is often called fall-through cases.