S
S
Sergey Bezrukov2018-09-09 13:30:57
Android
Sergey Bezrukov, 2018-09-09 13:30:57

Why does the script work differently in the compiled apk than in the unity editor?

There are lists of variables itemList, bonusList, both, mobileList.

public List<Item> itemList = new List<Item>();
    public List<Item> bonusList = new List<Item>();

    [HideInInspector]public List<Item> both = new List<Item>();

    public List<mobile> mobileList = new List<mobile>();
    [HideInInspector]public List<int> mobileCurCosts = new List<int>();
    [HideInInspector]public List<GameObject> mobileBtns = new List<GameObject>();

ItemList, bonusList and mobileList are needed for setting parameters through the inspector.
both - to combine itemList and bonusList (it's easier to calculate the necessary information this way).
Then the values ​​of these lists are assigned to the programmatically created buttons
. This is how the values ​​from the itemList and bonusList lists are assigned through both
for (int i = 0; i < usualCurCosts.Count; i++)
        {
            if (!both[i].isBonusPerSec)
                itemBtns.Add(Instantiate(prefab, shopPanels[1].transform));
            else
                itemBtns.Add(Instantiate(prefab, shopPanels[2].transform));
}

This is how mobileList is assigned.
for (int i = 0; i < mobileCurCosts.Count; i++)
        {
            var x = i;

            mobileBtns.Add(Instantiate(prefab, shopPanels[3].transform));
            mobileBtns[i].transform.GetChild(0).GetComponent<Text>().text = mobileList[i].name;

            mobileBtns[i].GetComponent<Button>().onClick.AddListener(delegate { buyMobile(x); });
        }

Problem: Everything works in the Unity editor. But in the compiled version, buttons are created only from mobileList, and there are simply no other buttons. What could be the problem or at least where to start looking for it?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question