Hi. Help to make an array of passwords. if doing as in the example. at the entrance to the server comes only “c”,. How to make that it was possible to choose from an array. Thank you
public void LaunchServer ()
{
string[] Password = new string[] { "a","b","c"};
for (int i = 0; i < Password.Length; i++)
Network.incomingPassword = Password*;*
}
It is because c
is being set as the incomingPassword
after others. You should make DropDown UI or something which allows to pick the password. Then you have to keep track of which password is chosen. Let’s say the index value of the drop down list is called index
. Then in LaunchServer
do Network.incomingPassword = Password[index];
.
Few notes:
- You should have the passwords array set not in the function, but instead just in the class. This allows to easily change the values in the inspector and makes it more efficient.
- You use the old networking system. It is bad. If you already have a big codebase then yes, you do not have a lot else to do. But if the networking code is not large, you will be able to convert to more efficient, secure and supported UNet system.