using UnityEngine; using UnityEngine.UI; public class ExpandableList : MonoBehaviour { public GameObject contentPanel; private bool isExpanded = false; // Start is called before the first frame update void Start() { // 为按钮设置点击事件 Button button = this.gameObject.GetComponent<Button>(); button.onClick.AddListener(OnClick); // 初始时将内容区域隐藏 contentPanel.SetActive(false); } // Update is called once per frame void Update() { } void OnClick() { isExpanded = !isExpanded; // 显示或隐藏内容区域 contentPanel.SetActive(isExpanded); } }