You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
2.2 KiB
71 lines
2.2 KiB
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Level05
|
|
{
|
|
public class AllToggleRgister : MonoBehaviour
|
|
{
|
|
public GameObject[] imgs;
|
|
public GameObject[] lable;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
imgs = new GameObject[transform.childCount];
|
|
lable= new GameObject[transform.childCount];
|
|
for (int i = 0; i < transform.childCount; i++)
|
|
{
|
|
imgs[i] = transform.GetChild(i).Find("selectedImg").gameObject;
|
|
lable[i] = transform.GetChild(i).Find("Label").gameObject;
|
|
}
|
|
|
|
for (int i = 0; i < transform.childCount; i++)
|
|
{
|
|
int index = i;
|
|
Toggle toggle = null;
|
|
|
|
toggle = transform.GetChild(i).GetComponent<Toggle>();
|
|
if (toggle != null)
|
|
{
|
|
transform.GetChild(i).GetComponent<Toggle>().onValueChanged.AddListener((bool a) =>
|
|
{
|
|
if (toggle.isOn)
|
|
{
|
|
|
|
/* for (int j = 0; j < imgs.Length; j++)
|
|
{
|
|
imgs[j].SetActive(false);
|
|
lable[j].GetComponent<Text>().color = Color.black;
|
|
}
|
|
*/
|
|
|
|
imgs[index].SetActive(true);
|
|
lable[index].GetComponent<Text>().color = Color.white;
|
|
}
|
|
else
|
|
{
|
|
imgs[index].SetActive(false);
|
|
lable[index].GetComponent<Text>().color = Color.black;
|
|
/*for (int j = 0; j < imgs.Length; j++)
|
|
{
|
|
imgs[j].SetActive(false);
|
|
lable[j].GetComponent<Text>().color = Color.black;
|
|
}
|
|
*/
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|