// Start is called before the first frame update void Start() { rigidBody = GetComponent <Rigidbody2D>(); sprite = GetComponent <SpriteRenderer>(); audioSource = GetComponent <AudioSource>(); candyDataList = FindObjectOfType <CandyDataHolder>().candyDataList; candySelectionUI.Setup(candyDataList); SelectCandy(0); }
public void Setup(CandyDataList candyList) { for (int i = 0; i < candyList.GetCount(); ++i) { CandySelectorUI newSelector = Instantiate(candySelectorPrefab, transform).gameObject.GetComponent <CandySelectorUI>(); newSelector.Setup(candyList.GetCandyDataObject(i), i + 1); candySelectors.Add(newSelector); } // Resize our component to fit everything RectTransform rectTransform = GetComponent <RectTransform>(); HorizontalLayoutGroup horizontalLayoutGroup = GetComponent <HorizontalLayoutGroup>(); float width = (selectorWidth * candySelectors.Count) + (horizontalLayoutGroup.spacing * candySelectors.Count - 1); rectTransform.sizeDelta = new Vector2(width, selectorHeight); rectTransform.anchoredPosition = new Vector2((width / 2) + (horizontalLayoutGroup.spacing * 2), rectTransform.anchoredPosition.y); }