每隔0.5s实例化一个预设,结束后等待0.5s,之后按顺序销毁预设
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using UnityEngine.UI;
public class Wait : MonoBehaviour {
public GameObject preNum;
public Transform preParent;
private GameObject[] orderObj = new GameObject[10];
void Start () {
float textX = preNum.transform.GetComponent<RectTransform>().localPosition.x;
StartCoroutine(waitCreate(0.5f, (int num) =>
{
GameObject obj = Instantiate(preNum) as GameObject;
obj.transform.parent = preParent.transform;
obj.transform.GetComponent<RectTransform>().localPosition = new Vector3(textX, 0, 0);
textX = obj.transform.GetComponent<RectTransform>().localPosition.x + 100;
obj.GetComponent<Text>().text = num.ToString();
orderObj[num] = obj