【发布时间】:2017-11-28 09:18:53
【问题描述】:
我正在开发一款激光防御游戏。
这是负责生成敌人的主要函数。我将变量 wave 设置为 3。然后我想破坏太空船的位置,以免它们产生。问题是当我开始游戏时根本没有船。
if (AllMembersDead())
{
for (float i = 0; i < waves; i++)
{
SpawnUntilFull(); // number of waves to be spawned
}
Destroy(position);
}
这是我销毁的游戏对象的图片:
如果需要,这里是 SpawnUntilFull() 和 AllMembersDead() 的函数。
bool AllMembersDead()
{
foreach(Transform childPositionGameObject in transform)
{
if (childPositionGameObject.childCount > 0)
{
return false;
}
}
return true;
}
void SpawnUntilFull()
{
Transform freePosition = NextFreePosition();
if (freePosition)
{
GameObject enemy = Instantiate(enemyPrefab, freePosition.transform.position, Quaternion.identity) as GameObject; // Instantiate (spawning or creating) enemy prefab (as gameobject assures that what its returning to us is no normal object but rather a game object)
enemy.transform.parent = freePosition; // the transform of whatever thing the enemy is attached to, and that would be the enemyFormation GameObject
}
if (NextFreePosition())
{
Invoke("SpawnUntilFull", spawnDelay);
}
}
我不确定我做错了什么。任何指导将不胜感激。
【问题讨论】:
-
在更新功能中。