using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class RoleItem : MonoBehaviour { private Toggle toggle; private string roleName; private Text roleText; private RoleSelectPanel roleSelect; private void Awake() { toggle = GetComponent(); roleText = transform.Find("Label").GetComponent(); } // Use this for initialization void Start () { roleSelect = transform.GetComponentInParent(); toggle.onValueChanged.AddListener(SetRole); } // Update is called once per frame void Update () { } public void SetItem(string role) { roleText.text = role; roleName = role; } private void SetRole(bool isOn) { if (isOn) { roleSelect.roleName = roleName; } } }