Linked Questions

Popular Questions

Explanation:

I have created a search field. When I type 3 letters, it searches from Firestore collection field tags and return the result which I instantiate it in a list. Screenshot attached below of the same

Search result and list image

The problem: I want to fetch the value of text I have clicked, but I am unable to get it.

Thanks in advance for you time.

The name of my script is search_riddhi.cs. Please guide me how can I achieve it and what wrong am I doing in my script ?

using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using System;
using Riddhi.utility.camera;
public class Search_riddhi : MonoBehaviour
{
    [SerializeField] Transform Content;
    [SerializeField] searchResult_riddhi SearchResult;
    [SerializeField] UnityEngine.UI.InputField field;
    Coroutine k;
    string itemName;

    private Camera cam;
    private GameObject pos;

    private void Update()
    {
       cam = GameObject.Find("MainCamera").GetComponent<Camera>();
        pos = GameObject.FindWithTag("Tv").GetComponent<GameObject>();
    }


    public void onEdit()
    {
        for (int i = 0; i < Content.childCount; i++)
        {
            Destroy(Content.GetChild(i).gameObject);
        }

        try
        {
            if (MainScreen.instance.objectInfoList.Count < 1) return;
        }
        catch
        {
            return;
        }
        
        if (k != null) StopCoroutine(k);
        if (string.IsNullOrEmpty(field.text))
        {
            k = null;
            return;
        }
        k = StartCoroutine(search());
    }
    IEnumerator search()
    {
        yield return null;
        foreach (var info in MainScreen.instance.objectInfoList)
        {
            if(info.tag.Contains(field.text))
            {
                Instantiate(SearchResult, Content).setDetails(info.name);
                SearchResult.GetComponent<Button>().onClick.AddListener(ItemClicked);
          
            }
        }
        k = null;

    }


    void ShowItemDetails()
    {
        // Show the item details for the clicked item here
        Debug.Log("Item Name: " + itemName);
    }



    void ItemClicked()
    {
        Debug.Log("Item clicked");
        Riddhi.utility.camera.Camera_Utility.FocusOn(cam,  pos,  1.5f);
        
    }
}

after clicking I dont see Debug.Log("Item clicked"); in console. Please guide

Related Questions