【问题标题】:Enemy spawn system. I want easy enemies to spawn first then medium after that i want hard enemies to spawn nonstop. i want it a endless spawn Please [closed]敌人生成系统。我希望先产生容易的敌人,然后再产生中等的敌人,然后我希望不断产生硬性的敌人。我想要一个无尽的产卵请[关闭]
【发布时间】:2016-10-27 14:36:55
【问题描述】:
  • 目前我的生成系统可以生成简单的然后中等的敌人,但是我遇到了 Array out of range 错误,它只生成了 4 个敌人。我想要 x20 简单(或一般数字)x20 中等,然后在(简单、中等和硬敌人之间随机)。

这是我的代码:

using UnityEngine;
using System.Collections.Generic;
using UnityEngine.UI;

public class Test : MonoBehaviour
{

public GameObject[] enemy; 

public Transform[] spawnPoints;         

private float timer = 2;


int index = 0 ;

int wave = 0;

List <GameObject> EnemiesList = new List<GameObject>();

private int enemyCount=20;


void Update()
{
    timer -= Time.deltaTime;

    if (timer <= 0 && wave < 6)
    {
        timer = 3;

        if (wave != 0 &&  wave % 2 == 0)
        {
            index ++ ;
        }

        EnemySpawner();

        wave++;
    }

}

void Spawn ()
{

    for (int i = 0; i<enemyCount;i++)
    {
        Invoke("EnemySpawner" , i + 2);
    }
}

void EnemySpawner ()
{
    int spawnPointIndex = Random.Range (0, spawnPoints.Length);

    GameObject InstanceEnemies= Instantiate ( enemy[index] , spawnPoints[spawnPointIndex].position , spawnPoints[spawnPointIndex].rotation) as GameObject;

    EnemiesList.Add(InstanceEnemies);

}

public void Remove (GameObject anything)
{
    EnemiesList.Remove (anything);
}

}

【问题讨论】:

  • 对于非常一般的问题,请尝试 gamedev.com 或 answers.unity3d.com。本网站仅针对特定的编程问题。

标签: c# unity3d system unity5


【解决方案1】:

我相信您需要将 enemyCount 变量设置为数组的长度。如果阵列中有 15 个敌人,而 enemyCount 仍然是 20 个呢?对我来说听起来像是 IndexOutOfRangeException。

【讨论】:

  • nop,作为测试,我将数组更改为 2 并将计数更改为 2,但我仍然遇到相同的错误。
猜你喜欢
  • 2023-03-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多