在一级按钮下实例化二级按钮(二级按钮在每次切换一级按钮时只有一个实例),且位置在一级按钮中心左侧:
public List<GameObject> A_Icon = new List<GameObject>();//二级按钮 public GameObject A_Icon_bg;//二级按钮板 void Start() { this.transform.GetComponent<Toggle>().onValueChanged.AddListener(Ischange); } private void Ischange(bool isTrue) { if (isTrue) { if (AIconbg.instanceTransform == null) { GameObject obj = (GameObject)Instantiate(A_Icon_bg, new Vector3(0, 0, 0), Quaternion.identity); AIconbg.instanceTransform = obj.transform; } Transform t = AIconbg.instanceTransform; t.SetParent(this.transform); t.localScale = Vector3.one; t.localPosition = new Vector3(-71, 0, 0); AIconbg.instanceTransform.gameObject.SetActive(true); } }