Help to make an array of passwords.
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[i];
}
Answer by AurimasBlazulionis · Oct 26, 2016 at 04:05 PM
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.
do not forget to accept the correct answers
Your answer
Follow this Question
Related Questions
[WebGL 2.0] Texture2DArray support? 1 Answer
Problem Destroying Component 0 Answers
Unable to load Json to an object array 1 Answer
reaching the limit of a Raycast[] array? 0 Answers
Similar function for each in array 1 Answer