Question by
sebastiants2008 · Jul 08, 2019 at 01:36 AM ·
buttontextsend-variable
send the text of a button as variable
Hello guys,
I'm creating a vertical list of buttons that are created based on the items in a php file and the Text change based on the items name, the list have an script to feed itself i want to send the Text when i click at the button that contains it to an object that displays the selected item name and another 2 parameters that can be displayed based on the player choices.
please see the script that fills the list below:
IEnumerator CreateItemsCoroutine(string jsonArrayString)
{
//parsing the jsonArrary as an array
JSONArray jsonArray = JSON.Parse(jsonArrayString) as JSONArray;
for (int i = 0; i < jsonArray.Count; i++)
{
//create local variables
bool isDone = false; //is it done?
string DiscountItem = jsonArray[i].AsObject["StockID"];
JSONObject itemNamejson = new JSONObject();
//create a callback to get the information from web.cs
Action<string> getDiscountCallback = (ItemName) =>
{
isDone = true;
JSONArray tempArray = JSON.Parse(ItemName) as JSONArray;
itemNamejson = tempArray[0].AsObject;
};
StartCoroutine(Main.Instance.Web.GetStock(DiscountItem, getDiscountCallback));
//Wait until the callback is called from WEB (inf finish dowloading)
yield return new WaitUntil(() => isDone == true);
//instantiate ameObject (Item Prefab)
GameObject stock = Instantiate(Resources.Load("PREFABS/stock") as GameObject);
stock.transform.SetParent(this.transform);
stock.transform.localScale = Vector3.one;
stock.transform.localPosition = Vector3.zero;
// fill the information
stock.transform.Find("Name").GetComponent<Text>().text = itemNamejson["Name"];
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612204521im_/https://answers.unity.com/themes/thub/images/avi.jpg)