教程地址(观看视频需FQ):
功能说明:如果有多种情况选择,可用switch进行切换
public class SwitchStatement : MonoBehaviour
{
void Start()
{
currentDifficulty = Random.Range(0, 3);
}
void Update()
{
switch(currentDifficulty)
{
case 0:
Debug.Log("You selected easy.");
break;
case 1:
Debug.Log("You selected medium.");
break;
case 2:
Debug.Log("You selected hard.");
break;
default:
Debug.Log("Invalid Level Selected!");
break;
}
if (Input.GetKeyDown(KeyCode.Space))
{
currentDifficulty = Random.Range(0, 4);
}
}