using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Optionsbox : MonoBehaviour { public Button anniu;//下拉框按钮 public Image Image; private GameObject game1; private GameObject game2; private GameObject game3; public List games = new List();//从Resources里加载出来下拉框的预设体 public List buttons = new List();//把克隆页面添加到链表中 public bool isp = true;//开关 public bool isp2 = true; public Transform weizhi;//需要克隆的位置 private Sprite sprite1;//需要替换的图片 private Sprite sprite2; void Start() { game1 = Resources.Load("UIPanel/subject1_iamg"); game2 = Resources.Load("UIPanel/subject2_iamg"); game3 = Resources.Load("UIPanel/subject3_iamg"); sprite1 = Resources.Load("sprite/三角形 绿"); sprite2 = Resources.Load("sprite/三角形白"); Debug.Log(sprite1); games.Add(game1); games.Add(game2); games.Add(game3); anniu.onClick.AddListener(() => { if (isp == true) { Image.sprite = sprite1; for (int i = 0; i < games.Count; i++) { Instantiate(games[i], weizhi); } for (int i = 0; i < 3; i++) { //获取生成的图片加载到页面 buttons.Add(GameObject.Find("Scroll_view_Drop").transform.GetChild(0).transform.GetChild(0).transform.GetChild(i).GetComponent()); // buttons.Add(transform.GetChild(3).transform.GetChild(0).transform.GetChild(0).transform.GetChild(i).GetComponent()); } isp = false; } else { if (isp2 == true) { Debug.Log(21); Image.sprite = sprite2; for (int i = 0; i < buttons.Count; i++) { buttons[i].gameObject.SetActive(false); } isp2 = false; } else { Image.sprite=sprite1; for (int i = 0; i < buttons.Count; i++) { buttons[i].gameObject.SetActive(true); } isp2 = true; } } }); } }