我希望让敌人以5到15秒之间的随机间隔产生.
这是我现在的代码.我在预制敌人身上有移动/变换脚本.
using UnityEngine;
using System.Collections;
public class Spawner : MonoBehaviour {
public float spawnTime = 5f; // The amount of time between each spawn.
public float spawnDelay = 3f; // The amount of time before spawning starts.
public GameObject[] enemies; // Array of enemy prefabs.
public void Start ()
{
// Start calling the Spawn function repeatedly after a delay .
InvokeRepeating("Spawn", spawnDelay, spawnTime);
}
void Spawn ()
{
// Instantiate a random enemy.
int enemyIndex = Random.Range(0, enemies.Length); …Run Code Online (Sandbox Code Playgroud)