public List<Wave> WaveCount = new List<Wave>();
public class Wave
{
public GameObject EnemyPrefab;
public int EnemiesCount = 10;
public float spawnRate = 1;
}
thats all ok, I know how to do things with it, but now I want to do something like
public GameObject EnemyPrefab[];
and make for each prefab in the array EnemiesCount property. How?
You could do something like this. I think this is what you’re asking for.
public List<Wave> WaveCount = new List<Wave>();
public class Wave{
public GameObject EnemyPrefab;
public int EnemiesCount = 10;
public float spawnRate = 1;
}
Wave waveItem = new Wave();
WaveCount.Add( waveItem );
Edit:
Sorry, I think i misread what you wanted to do.
Basically you want a List of all the waves, and in each wave you want to create a set amount of enemies?
Something like this, but maybe in more simple way?
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Test : MonoBehaviour
{
public List<Test1> T1 = new List<Test1>();
}
[System.Serializable]
public class Test1
{
public List<Test2> T2 = new List<Test2>();
public float thefloat;
}
[System.Serializable]
public class Test2
{
public GameObject GO;
public int i;
}
you can still use public GameObject[ ] EnemyPrefab;
for example public GameObject[ ] EnemyPrefab = new GameObject[10];
that will create spaces for 10 items in the array. Are you planning on adding the enemy prefabs by code or in the inspector?
I’m going to have to assume some things here, since you didnt really answer the questions i asked in my 2 posts, but I think your second bit of code should work.
If you are using the inspector to add the EnemyPrefab, then you should probably just use the built in array instead of a list. But what you posted should work fine, unless there’s something I’m missing.
Then something like this should work for your purposes.
// class that attaches to your GameObject
public class WaveSpawn : MonoBehaviour{
public List<Wave> WaveCount = new List<Wave>();
}
[System.Serializable]
public class Wave
{
public Enemy[] EnemyPrefabs;
public int EnemiesCount = 10;
public float spawnRate = 1;
}
[System.Serializable]
public class Enemy{
public GameObject enemyPrefab;
public int id;
}