Enemy classes involved:
public abstract Enemy : MonoBehaviour {}
public class A : Enemy {}
public class B : Enemy {}
I have a dictionary. I want make the dictionary contain a stack for every type of Enemy.
public class Test : MonoBehaviour
{
// prefabs
public GameObject a, b;
public Dictionary<Enemy, Stack> eDictionary;
void Start()
{
eDictionary = new Dictionary<Enemy, Stack>();
Fill(a, 10);
Fill(b, 10);
}
}
How I make the stack and keys.
public void Fill(Enemy e, int howMany)
{
Stack s = new Stack();
for(int I = 0; I < howMany; I++)
{
GameObject g = MonoBehavior.Instantiate(e.gameObject) as GameObject;
s.Push(g);
}
eDictionary.Add(e, s)
}
The main problem is: How do I make the keys in such a way that the Enemies of type A stack together with 1 key?
When I go into the generalized
enemy classes A and B and try to add that enemy to the corresponding stack due to its key, I get key not matching error. I do this when I pop the Enemies out of the stack then when I am done with them I want to push them into the dictionary's stack (it fails at that point).