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 Tower Defenseゲームを作ろうとしています。これらの2つの方法は、レベルの敵の値を0.5秒間隔で5発生成する必要があります。私はそれをデバッグし、コードを実行しますが、私はちょうど新しいgameobjectsを取得しません。ユニティでゲームオブジェクトを生成できない
私は例:Youtube(brackeys)と彼のTower Defense Tutorialで解決策を探しましたが、私は間違いを見つけられません。
ありがとうございました。 Mika。
Unityで 'System.Random'を呼び出す必要はありません。組み込みの' UntityEngine.Random'を代わりに使用してください。 –
このコードでは本当に問題はありません。 'System.Random'は問題ありません。 –
ゲームを実行していた階層は、あなたが望んでいるものと異なる位置に産卵しているかもしれません。 – CNuts