The way I handled the random

I enjoyed using If statements more then switch honestly.

bool isValidLevelNumber = (input == “1” || input == “2”);
if(isValidLevelNumber)
{
level = int.Parse(input);
StartGame();
}
if (input == “1”)
{
password = level1Password[Mathf.FloorToInt(Random.Range(0, level1Password.Length))];
//password = level1Password[2];
StartGame();
}
else if (input == “2”)
{
password = level2Password[Mathf.FloorToInt(Random.Range(0, level2Password.Length))];
StartGame();

    }

This worked well for me.

1 Like

Nice. In general, I’m a big fan of iFs, but you’ll eventually find a good place to use a switch, I’m sure. Keep t it!

Privacy & Terms