Yup, since you made the data set in “pairs” that’s going to be required. One thing that is probably in the next lecture, but I’m noticing it so I’ll mention it: you can make the code more robust with a small change, such as:
case 1:
password = level1Passwords[Random.Range(0, level1Passwords.Length)];
break;
This allows you to add/remove list members, without getting errors such as index out of range, or the omission of members above the “magic-number” range you specify for each case.
My next suggestion is to ignore the above and just continue the course; as I say, I’m pretty sure you’ll be covering it or something similar soon enough. By the same token, ignore the following comments as well (lol) because I feel compelled to say a word about your level 3 “issue” where you need to assign the temporary int index variable to make use of it twice…
Firstly, there is nothing wrong with doing it the way you’ve done it. While it leaves you with the need to maintain the two independent lists, yet synchronously, it’s only two small lists so it’s what we call, “Not a big deal.” BUT, you could do something like use a struct or a class that can contain both the password and the hint together, providing an improved readability/maintainability for the data structures, perhaps…
I’m just winging it here, but your case 3: could be something like:
case 3:
MetaData thisMeta = GetMetaThree();
password = thisMeta.password;
hint = thisMeta.hint;
break;
It would require a bit of structure underlying it, but if you were planning to do much in the way of extending the variety of passwords, I think it would pay-off because it’s really bloody obvious
what data goes where:
private class MetaData
{
public string password = "defaultPassword";
public string hint = "defaultHint";
}
private const int LEVEL_3_MEMBER_COUNT = 3;
private MetaData[] levelThreeMeta = new MetaData[LEVEL_3_MEMBER_COUNT];
private void InitLevelThreeMeta()
{
levelThreeMeta[0].password = "discombobulated";
levelThreeMeta[0].hint = "John didn't want to be LATE; he quickly COMBed his office for the DISC.";
levelThreeMeta[1].password = "password2";
levelThreeMeta[1].hint = "hint2";
levelThreeMeta[2].password = "password3";
levelThreeMeta[2].hint = "hint3";
}
private MetaData GetMetaThree()
{
int index = Random.Range(0, LEVEL_3_MEMBER_COUNT);
MetaData metadata = new MetaData();
metadata.password = levelThreeMeta[index].password;
metadata.hint = levelThreeMeta[index].hint;
return metadata;
}
private void Start()
{
InitLevelThreeMeta();
}
Of course, as you will soon learn, there are a million and a half ways to do anything when it comes to programming; I have no doubt there are far better ways to manage your password/hint pairs, but this is what came to mind when I read your post.