Hi people,
I’m working on a very simple networking game, but I want to add a feature where by if a player enters in an offensive name for their character, show a message that they can’t use that name.
So far I have…
private string[] bannedNames = new string[] {"Banned", "SoBanned"};
if(charName == bannedNames.ToString())
{
Debug.LogError("no");
}
private string[] bannedNames = new string[] {"Banned", "SoBanned"};
foreach(string badName in bannedNames){
if(charName == badName.ToString())
{
Debug.LogError("no");
}
}
to check charName against all names in bannedNames array
you shouldn’t have to ‘ToString’ badName, it’s already a string.
Also, you may want to do a ‘contains’ instead, and also to do it case insensitively (in that current technique we block Banned, but not BANNED).
1 Like