主要内容: 1、实现点击button后出现UI,两秒后UI消失。方法一:协程;方法二:计时器
方法一:协程
private void OnClickButtonBeginBtnDown() { for (int i = 0; i < listDice.Count; i++) { listDice[i].timer = 0; } if (listDice.Count > 6) { textTip.SetActive(true); StartCoroutine(enumerator()); } } IEnumerator enumerator() { yield return new WaitForSeconds(2); textTip.SetActive(false); }
方法二:计时器
private void Update() { CloseUI(); if (timeKeeping == true) { TimeKeeping(); } } //计时 public void TimeKeeping() { timer += Time.deltaTime; if (timer > 5) { for (int i = 0; i < listNumberUI.Count; i++) { Instantiate(listNumberUI[i], CardList.transform); } timeKeeping = false; timer = 0; listNumberUI.Clear(); } }