FragMate CommunityLog in

FragMate - Software and Game Developer Community, including Resources, Forums, Marketplace & More.

Share

description wave spawnig

more_horiz
hey guys do enyone have a script that can spawn enemy in wave it with well really be helpful

descriptionRe: wave spawnig

more_horiz

Code:

 public GameObject enemy;
 
    private bool waveActive = false;
 
    public Transform[] spawnPointRoot;
 
    private int waveLevel = 0;
    private float diffucultyMultiplier = 1.0f;
    private float intermissionLength = 10f;
    private int enemyCount = 0;
    private ArrayList enemies;
    private bool allEnemiesSpawned = false;
 
    private float velocity = 4f;
    private float health = 20f;
    private int enemyAmount = 10;
    private float spawnIntervall = 2;
 
    private GUIScript gui;
 
    public enum GameState {
      preStart,
      activeWave,
      intermission
    }
 
    GameState state = GameState.preStart;
 
    void Start(){
      enemies = new ArrayList();
      gui = Camera.main.GetComponentInChildren<GUIScript>();
    }
 
    void Update () {
      switch(state){
 
        case GameState.preStart:
          if(gui.startWave){
              setNextWave();
              startNewWave();
              gui.startWave = false;
          }else {
 
          }
        break;
 
        case GameState.activeWave:
          if(enemyCount == 0 && waveActive && allEnemiesSpawned){
              finishWave();
          }
        break;
 
        case GameState.intermission:
        break;
      }
    }
 
    void LateUpdate(){
      for(int i = 0; i < enemies.Count; i++){
        if((GameObject)(enemies[i]) == null){
          enemies.Remove(enemies[i]);
        }
      }
      enemyCount = enemies.Count;
    }
 
    void setNextWave(){
      diffucultyMultiplier = (diffucultyMultiplier * waveLevel) / 2;
    }
 
    void startNewWave(){
      state = GameState.activeWave;
 
      StartCoroutine(StartMission(1.5f));
 
      waveLevel++;
    }
 
    IEnumerator InterMission(float seconds){
      yield return new WaitForSeconds(seconds);
      setNextWave();
      startNewWave();
    }
 
    IEnumerator EnemySpawnerRoutine(float spawnIntervall, int enemyAmount, float velocity, float health){
      for(int i = 0; i < enemyAmount; i++){
        spawnNewEnemy(velocity, health);
        yield return new WaitForSeconds(spawnIntervall);
      }
      allEnemiesSpawned = true;
    }
 
    void finishWave(){
      StartCoroutine("InterMission",intermissionLength);
      state = GameState.intermission;
      waveActive = false;
    }
 
    void spawnNewEnemy(float velocity, float health){
      GameObject e = (GameObject) Instantiate(enemy, new Vector3(0,0,0), Quaternion.identity);
      EnemyScript es = e.GetComponentInChildren<EnemyScript>();
      int i = Random.Range(0,2);
      es.setWaypoints(spawnPointRoot[i]);
      es.maxHealth = health;
      es.currHealth = health;
      es.speed = velocity;
      enemyCount++;
      enemies.Add(e);
    }
 
    IEnumerator StartMission(float seconds){
      yield return new WaitForSeconds(seconds);
 
      allEnemiesSpawned = false;
 
      StartCoroutine(EnemySpawnerRoutine(spawnIntervall,enemyAmount,velocity,health));
 
      waveActive = true;
    }

descriptionRe: wave spawnig

more_horiz
I got 21 error when i past this code in my game can you look this code over and send it back to me or tell me what i need to do so it can work

descriptionRe: wave spawnig

more_horiz
Its easy to make the script but what kind of game are you making? B/c it depends on the type of the game
Permissions in this forum:
You cannot reply to topics in this forum