I am trying to make a simple search and reveal for an inventory, wondering if there is a better way to do this? This is attached to the parent Gameobject and works with an InputField to compare the text in the field and the name of the Gameobjects, in order to show and reveal them.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Linq;
public class findFrame : MonoBehaviour
{
public InputField searchText;
void Find()
{
var found = new List<GameObject>(GameObject.FindGameObjectsWithTag("Button")).Where(g => g.transform.IsChildOf(this.transform));
foreach (GameObject g in found)
{
Debug.Log("hello");
if (g.transform.name != searchText.text)
{
gameObject.SetActive(false);
}
else
{
gameObject.SetActive(true);
}
}
}
void Update()
{
Find();
}
}