How can I really make a Search Bar/Searcher for Unity?

Alright here’s what i mean. Say i’m making a card game right. And I want to make a scene only for Customizing and editting your deck. I looked at previous amount of things to try and help me, but it wasn’t enough for me. So what i want is to find certain cards that contain the following name, typed in the text area. For Example. I type in Knight, and i want it load the following cards that have the word Knight in it. Such as Knighterlight, Knight Ring, Extreme Knight, Knightrous. All that good stuff.

HERE’S MY CODE. I’d appreciate the help please.

var searchString = "";
var items : GameObject;
function OnGUI()
{
   searchString = GUI.TextField (Rect (25, 25, 100, 30),searchString);
   
   
   
   
      // Do comparison here. For example
   for (var i = 0; i < searchString.Length; i++)
   {
         if (searchString.Contains(items.name));
      {
         GUI.Label(Rect (50, 50, 210, 80),"Label");
      }
   }
}

In my Items Variable i have a cube Gameobject named Hello in there.
I have my GUI.Label named “Label” To see if the program will run through simply. But so far it just failed every time…

There are a few problems with your code, the main one being:

searchString.Contains(items.name)

What this does is asks if searchString has items.name somewhere within it, I think you want to look at the items.name (Knight Ring) and check if it contains searchString (Knight) and then return true.

The other minor problem though one that probably is causing as much trouble is the semicolon (:wink: at the end of your if statement. What this is doing is saying check the if but don’t use the answer for anything. Then you show a GUI.Label without any reference to the if statement, it will not throw an error as you still have properly closed out brackets {}.

Another mistake is that your variable ‘items’ should be a list rather than a single GameObject instance, to do that you do var items : GameObject;

Scribe

P.S.

As @getyour411 said, next time you should highlight all your code and hit the 101010 button to make sure it keeps the correct formatting. I have a feeling you need 5 karma to edit your own questions so I will change it this time.