using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; public class AutoZH : MonoBehaviour,IPointerClickHandler { public List zhList; private int index = 0; // 设置当前菜单索引 // Start is called before the first frame update private void OnEnable() { StartCoroutine(MouseIdleCoroutine()); } public void OnPointerClick(PointerEventData eventData) { // StartCoroutine(MouseIdleCoroutine()); } private IEnumerator MouseIdleCoroutine() { while (true) { if (index >= zhList.Count) { index = 0; // 回到第一个菜单 } PointerEventData pointerEventData = new PointerEventData(EventSystem.current); GameObject mGameObject=zhList[index]; // 获取当前菜单对象 mGameObject.GetComponent().OnPointerClick(pointerEventData); mGameObject.GetComponent().OnPointerClick(pointerEventData); index++; // 切换到下一个菜单 // 等待指定的闲置时间 yield return new WaitForSeconds(15f); } } }