我每个人都反复产生敌人1.75f。但是我不知道如何使用随机函数。我的原型游戏就像Chrome浏览器中的游戏,当找不到页面时就会显示。
感谢你们对我的帮助。
这是我的代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyGeneratorController : MonoBehaviour
{
public GameObject enemyPrefeb;
public float generatorTimer = 1.75f;
void Start ()
{
}
void Update ()
{
}
void CreateEnemy()
{
Instantiate (enemyPrefeb, transform.position, Quaternion.identity);
}
public void StartGenerator()
{
InvokeRepeating ("CreateEnemy", 0f, generatorTimer);
}
public void CancelGenerator(bool clean = false)
{
CancelInvoke ("CreateEnemy");
if (clean)
{
Object[] allEnemies = GameObject.FindGameObjectsWithTag ("Enemy");
foreach (GameObject enemy in allEnemies)
{
Destroy(enemy);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)