Search Unity

Identify an array index of a prefabs when clicked

Discussion in 'Prefabs' started by ljimene29, Apr 4, 2019.

  1. ljimene29

    ljimene29

    Joined:
    Jan 20, 2017
    Posts:
    2
    Hi, I have a prefab which clone, this prefab has the TextMeshPro component and I use it like this: I read the data from a json file remotely and that information is shown in the prefab through the TextMeshPro component. As you can see in the image, the information is highlighted in red.



    And here I show a code fragment of how I read and show the data. This code is inside a coroutine

    Code (CSharp):
    1.  
    2. options = GameObject.Find("Opciones");//GameObject parent
    3. float PosZ = 0.025f;
    4. for (int i = 0; i < jsonNode[ciudad][0][boton][0][opcion2].Count; i++)
    5.     {
    6.  
    7.        lblOpcion.GetComponent<TextMeshProUGUI>().text = jsonNode[ciudad][0][boton][0][opcion2][i]["nombre"];
    8.  
    9.        childObject = Instantiate(lblOpcion);
    10.  
    11.        childObject.transform.localScale = Vector3.one;
    12.  
    13.        childObject.transform.position = new Vector3(0.008f, 10.2f, PosZ);
    14.  
    15.        childObject.transform.SetParent(options.transform, false);
    16.  
    17.        PosZ -= 0.10f;
    18.  
    19.         }
    20.  
    All this works well. But now what I need to do and I have not been able to, is that by clicking on any of the options ("INVIERNO","PRIMAVERA","VERANO" or "OTONO"), show me the array index of the prefab when it is done click.

    If someone can give me an idea of how to do it, I'll be grateful.