Checking that this String is in this Array

Hi, i want to make something like cheat console using text field and array of cheats strings. And when i type for example player.kill in text field unity will search if this string is in Cheats
Strings Array and make an Label “Succeed” when it is and “Failed” when it’s not.

Thanks in advance and sorry for my English.

You don’t need to loop through arrays or anything, just use IndexOf, which returns -1 if the item isn’t found.

var strings = ["yo", "blah", "foo"];
if (System.Array.IndexOf (strings, "blah") != -1) {
	Debug.Log ("Yep.");
}

Or better yet, assuming you’re using a recent version of Unity, Array.Contains:

var strings = ["yo", "blah", "foo"];
if (strings.Contains ("blah")) {
	Debug.Log ("Yep.");
}

So make your array of strings and loop through them whilst comparing them to what the user typed.
You can compare them with “==

It’s pretty straigtforward and trivial to translate what you wrote into a functioning script if you know anything about scripting at all.

Just off the top of my head:

   var cheatStrings : String[];

   var testString : String = consoleDisplay.text;
   var isValid : System.Boolean = false;
   for (var s : int = 0; s < cheatStrings.Length; s++)
        {
        if (testString == cheatStrings~~)~~

{
isValid = true;
}
}
if (isValid)
{
Debug.Log “Succeed”;
}
else
{
Debug.Log “Failed”;
}
So, if something like that didn’t just come to you when you thought about the problem, you will have a lot more difficulties ahead of you and before taking on the game you want to make, you need to read and reread the Unity scripting reference, as well as freshen up on programming in general.