Quantcast
Channel: Questions in topic: "clone"
Viewing all articles
Browse latest Browse all 508

How to fix button clones that aren't working?

$
0
0
I have buttons that are made on startup and given a onclick listener etc, but when you try to click them in game they are completely ignored as if they aren't even there and it just hits the panel behind them, the button to open the store works perfectly, I did it so they change colour when pressed and highlighted and only the store button changed. I will post the code for the classes if it has something to do with them. This is my first class (ShopItemHandler) public GameObject button; int counter; public ItemScript ItemScript; [System.Serializable] public class Item { public string objectName; public float cost; public float gain; public int count; } public GameObject[] buttonItems; public Item[] shopItems; // Use this for initialization void Start () { buttonItems = new GameObject[shopItems.Length]; counter = 0; foreach (Item i in shopItems) { GameObject btn = (GameObject)Instantiate (button); buttonItems [counter] = btn; ItemScript scp = btn.GetComponent (); scp.objectName.text = i.objectName; scp.cost.text = "Cost: " + i.cost.ToString("F1"); scp.count.text = i.count.ToString(); scp.gain.text = "Eggs/S: " + i.gain.ToString("F1"); btn.transform.SetParent(transform, false); Item thisItem = i; scp.thisButton.onClick.AddListener (() => Purchase(thisItem)); counter++; } } public void Purchase (Item Bought) { Bought.count++; Bought.cost = Bought.cost * 1.2f; updateItems (); } void updateItems () { counter = 0; foreach (Item i in shopItems) { ItemScript scp = buttonItems[counter].GetComponent (); scp.objectName.text = i.objectName; scp.cost.text = "Cost: " + i.cost.ToString("F1"); scp.count.text = i.count.ToString(); scp.gain.text = "Eggs/S: " + i.gain.ToString("F1"); counter++; } } // Update is called once per frame void Update () { } And this is the class script for the buttons/Items (ItemScript) public Text objectName; public Text cost; public Text gain; public Text count; public Button thisButton; // Use this for initialization void Start () { thisButton.gameObject.SetActive (true); } // Update is called once per frame void Update () { }

Viewing all articles
Browse latest Browse all 508

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>