32 lines
744 B
C#
32 lines
744 B
C#
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
|
||
|
public class TestAnimation : MonoBehaviour
|
||
|
{
|
||
|
public GameObject prefab; // 拖放预制体到这个变量
|
||
|
public int maxCount = 15; // 最大创建数量
|
||
|
|
||
|
private void Start()
|
||
|
{
|
||
|
StartCoroutine(SpawnPrefabs());
|
||
|
}
|
||
|
|
||
|
private IEnumerator SpawnPrefabs()
|
||
|
{
|
||
|
int count = 0;
|
||
|
|
||
|
while (count < maxCount)
|
||
|
{
|
||
|
// 随机生成时间间隔
|
||
|
float waitTime = Random.Range(0.5f, 1.5f);
|
||
|
yield return new WaitForSeconds(waitTime);
|
||
|
|
||
|
// 创建预制体
|
||
|
Instantiate(prefab, transform.position, Quaternion.identity);
|
||
|
|
||
|
count++; // 增加计数
|
||
|
}
|
||
|
}
|
||
|
}
|