private void AddAnswerButtons() { RemoveAnswerButtons(); List <Words2Image> temp = circleImages.ToList(); Words2Image btn = temp.First((b) => b.id == circleButtons[wheel.activeCircle].prefab.id); temp.Remove(btn); btn = temp.First((b) => b.id == circleButtons[wheel.activeCircle].prefab.pair.id); temp.Remove(btn); int randomIndex = UnityEngine.Random.Range(0, 3); for (int i = 0; i < 3; i++) { Words2Image prefab = null; GameObject go = null; if (i != randomIndex) { int ci = UnityEngine.Random.Range(0, temp.Count); prefab = temp[ci]; temp.RemoveAt(ci); } else { prefab = circleButtons[wheel.activeCircle].prefab.pair; } go = Instantiate(prefab.gameObject); Words2Image img = go.GetComponent <Words2Image>(); Words2ImageButton button = go.AddComponent <Words2ImageButton>(); button.SetStates(img.normal, img.down, img.wrong); button.index = i; button.prefab = prefab; button.onClick += AnswerButtonOnClick; go.transform.position = buttonsPoints[i].position; go.transform.localScale = new Vector3(0.807f, 0.807f, 0.807f); answerButtons.Add(button); } }
private void AddCircleImages() { List <Words2Image> temp = circleImages.ToList(); for (int i = 0; i < 6; i++) { int index = UnityEngine.Random.Range(0, temp.Count); GameObject go = Instantiate(temp[index].gameObject); Words2Image img = go.GetComponent <Words2Image>(); Words2ImageButton button = go.AddComponent <Words2ImageButton>(); button.SetStates(img.normal, img.down, img.wrong); button.index = i; button.prefab = temp[index]; button.onClick += CircleImgageButtononClick; go.transform.localScale = new Vector3(0.6248479f, 0.6248479f, 0.6248479f); circleButtons.Add(button); temp.RemoveAt(index); } wheel.SetWheelButtons(circleButtons); }