- Home /
wave list into list or( list into array)
Hello,
i have problem to make list into list.
i need because i have made so every wave have different monsters and i have multiple waves.
So i need list what contains my wave list like so : waves{wave1,wave2,wave3}
i have code that change wave 1 to wave 2
when i have wave[0] and its ended then i call wave[1].
is there way to make list in list ?
code is here :
GameObject[] waveykskollid = { vastane1, vastane2, vastane2, vastane2 };
wave1.AddRange(waveykskollid);
GameObject[] wavekakskollid = { vastane3, vastane3, vastane3, vastane3 };
wave2.AddRange(wavekakskollid);
List[] waved = { wave1, wave2 };
myList.AddRange(waved);
Answer by RobAnthem · Mar 18, 2017 at 09:31 PM
You can always make an embedded list or multidimensional array.
List<List<Wave>> waves;
Wave[][] waves;
can you write some example how to do it ?
i'm not so skillful yet, i need some example code to understand it.
i searched on google but i didn't really get it, i tried few different ways but none of them worked.
i don't get how i can add 1 list into bigger list.
this code is in start():
void Start() {
StartCoroutine(SpawnWaves());
GameObject[] waveykskollid = { vastane1, vastane2, vastane2, vastane2 };
wave1.AddRange(waveykskollid);
wave = wave1;
GameObject[] wavekakskollid = { vastane3, vastane3, vastane3, vastane3 };
wave2.AddRange(wavekakskollid);
//List[] waved = { wave1, wave2 };
//myList.AddRange(waved);
}
Answer by ExtinctSpecie · Mar 19, 2017 at 11:21 AM
public class TestWave
{
List<GameObject> minionsOfWave = new List<GameObject> ();
public TestWave()
{
}
public void AddMinion(GameObject minion)
{
minionsOfWave.Add (minion);
}
public List<GameObject> GetMinions()
{
return minionsOfWave;
}
public void PrintWave(List<GameObject> minions)
{
}
}
public class WaveManager : MonoBehaviour
{
List<TestWave> myWaves;
TestWave wave;
// populate these through inspector
public List<GameObject> wave1;
public List<GameObject> wave2;
void Start()
{
myWaves = new List<TestWave> ();
CreateWaves (wave1);
CreateWaves (wave2);
PrintWaves ();
}
public void CreateWaves(List<GameObject> waveTemp)
{
wave = new TestWave ();
foreach( GameObject minion in waveTemp)
{
wave.AddMinion (minion);
print ("added minion to wave : " + minion.name);
}
myWaves.Add (wave);
}
public void PrintWaves()
{
foreach (TestWave wave in myWaves)
{
int i=1;
foreach (GameObject minion in wave.GetMinions())
{
print ("wave #: " + i + minion.name);
}
}
}
}
just some temporary code to give you a view of how you could achieve your goal
I forgot to increment I in the PrintWaves method i++;
Answer by Bafelmauk · Mar 19, 2017 at 02:32 PM
i think you codes are too hard for me i'm really noob.
but i am thankful you responded my question it made me keep trying and it made me search different questions from google what i could not think on my own.
i got it work kinda how i needed but i don't know is it best way to do it.
i tried this code almost the same as yesterday but there was some sort of mistake in this code. I took some good night sleep and today it worked.
here is code that worked for me:
List<List<GameObject>> wavedkokku = new List<List<GameObject>>();
wavedkokku.Add(wave1);
wavedkokku.Add(wave2);
wave = wavedkokku[0];
thanks for replay!