void Spawnwave()
{
//Standard unit is lvl1 unit
int saverUnit = 1;
int saverPossibilty = 100;
System.Random randy = new System.Random();
//This for gets the possibility for the first possible enemy
for (int i = 0; i < possibilty.Length; i++)
{
if (possibilty[i] != 0)
{
saverUnit = i;
saverPossibilty = possibilty[i];
break;
}
}
//As only 2 kind of units per wave can be spawned +1 spawns the "stronger" one
for (int i = 0; i < level+5; i++)
{
if (randy.Next(100) > saverPossibilty)
{
StartCoroutine(SpawnUnit(saverUnit + 1));
}
else
{
StartCoroutine(SpawnUnit(saverUnit));
}
}
}
IEnumerator SpawnUnit(int unit)
{
Instantiate(enemies[unit],spawnPoint.position, spawnPoint.rotation);
yield return new WaitForSeconds(timeBetweenEnemies);
}
所以我想制作一个Unity塔防游戏。这两种方法应该以0.5秒的间隔产生5+等级敌人的价值。我调试了它,它通过代码运行,但我没有得到任何新的gameobjects。不能在Unity中产生游戏对象
我试图寻找例如:Youtube(括号)和他的塔防教程的决议,但我仍然无法找到我的错误。
感谢您的帮助, Mika。
您应该永远不需要在Unity中调用'System.Random',而是使用内置的'UntityEngine.Random'。 –
我无法真正看到此代码的任何问题。 'System.Random'很好。 –
你看过层次结构吗?游戏运行时,你的对象可能只是在不同的位置产生,然后是你所期待的。 – CNuts