Dynamic buttons with an array from firebase URL links
I need to add several openurl events in an array of buttons, created within a canvas. I'm reading the data from a firebase and all instantiate the items successfully. To instatiate the gameobject (a game object with a canvas and texts, images, and 3 buttons) am using the code below.
uxPrefab.SetActive(true);
GameObject merchants = Instantiate(uxPrefab, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
merchants.transform.parent = GameObject.FindWithTag("content").transform;
merchants.name = name;
The gameobject with the canvas layout is instancing 55 times, the total of the entries on Firebase. The button "web" is in all instances. I debugged the code an all the links has been loaded and stored in a variable for each item instanced.
var link = childSnapshot.Child("weblink").Value.ToString();
Debug.Log("Button Link: " + link);
The problem I'm having is that every button have the same urls, always the last one loaded from the list. How can I have the link for each button? So when I click the button on item 1 button and then OpenURL of item 1, and click on the item 2 button and then OpenURL for the item 2, etc. I tried to pass the link to a second script:
public void WebLinkDB(){
GameObject linkbutton = GameObject.FindGameObjectWithTag("firebasedb");
Debug.Log("Button Exists");
FirebaseDB linkbutt = linkbutton.GetComponent<FirebaseDB>();
Debug.Log("FirebaseDB Exists");
linktotal = linkbutt.linkURl.ToString(); //PlayerPrefs.GetString(nameM);
Debug.Log("Loaded from PlayerPrefs: " + linktotal);
Application.OpenURL(linktotal);
}
but it's not working the linktotal is null.
Thare's any way to make it in the same script and instantiate the button with the proper openURL string on it?
Thanks
Your answer
Follow this Question
Related Questions
How to compare a position of an object within an array 1 Answer
Array problem, I'm novice 1 Answer
C# ArrayList Accessing and RemoveAt? 0 Answers
Getting an error when using an Array of String Arrays 0 Answers
condition for array of textures 1 Answer