- Home /
Dynamic link url and text in WebGL build
Hello, the idea is:
The game should display a list of links (text + button on which the link script hangs). It should be possible to change these links with the text after the publication.
That is, store the text + link in json or xml on the server and that would build them up when loading ...
The question is, which method is the best / easier to implement? I will be grateful for the tip in the direction of what to watch.
Answer by upasnavig90 · Feb 12, 2018 at 11:16 AM
Make a prefab , instantiate at run time for all the links you have and use onClick.AddListener with the parameter of link u want to open.
you can check it on https://docs.unity3d.com/ScriptReference/UI.Button-onClick.html
this might be helpful for you:
foreach (var item in links) {
GameObject newlink = GameObject.Instantiate (linkPrefab)as GameObject;
newlink.GetComponent<Button> ().onClick.AddListener (()=>OnClickDenomination (yourLink));
}
The difficulty is that at the time of the build I have no references. I need to build build links and text that I can change without making a new build ... What option is there to take this list of references remotely?
Answer by digitalmkt · Jun 25, 2019 at 09:00 PM
I'm having the exactly same problem, did you solve it? Thanks.
I'm using firebaseDB to list all the links and name and more information, maybe this can help:
FirebaseApp app = FirebaseApp.DefaultInstance;
app.SetEditorDatabaseUrl("https://passportibiza-211918-82da1.firebaseio.com/");
Debug.Log("Firebase DB Found");
FirebaseDatabase.DefaultInstance
.GetReference("merchants")
//.StartAt(0)
.OrderByValue()
.ValueChanged += (object sender2, ValueChangedEventArgs e2) =>
{
if (e2.DatabaseError != null)
{
Debug.LogError(e2.DatabaseError.Message);
}
if (e2.Snapshot != null && e2.Snapshot.ChildrenCount > 0)
{
foreach (var childSnapshot in e2.Snapshot.Children)
{
//Population the var with data from DB
Debug.Log("Gathering Data");
var address = childSnapshot.Child("address").Value.ToString();
var cat = childSnapshot.Child("category").Value.ToString();
//var incorp = childSnapshot.Child("incorporation").Value.ToString();
var phone = childSnapshot.Child("phone").Value.ToString();
var nameM = childSnapshot.Child("venue").Value.ToString();
//var link = childSnapshot.Child("weblink").Value.ToString();
List<string> link = new List<string>() { childSnapshot.Child("weblink").Value.ToString() };
for (int i = 0; i < link.Count; i++)
{
Debug.Log("Lin URL array: " + link[i]);
weblink(link[i]);
++i;
break;
}
// Assigning UI elements and populating data from VARs
addressField.text = address;
catField.text = cat;
phoneFIeld.text = phone;
nameField.text = nameM;
//Instantiating the UI elements based on DB entries
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 = nameM;
}
}
Your answer
Follow this Question
Related Questions
how to change the maintexture from another scene? 1 Answer
WebGL WWW and Localhost CORS 0 Answers
Max String Length in WWW url's? 1 Answer
WWW.EscapeURL Not Work Well? 2 Answers
location of file downloaded with WWW 1 Answer