Question by
jin706457491 · Oct 01, 2021 at 10:37 PM ·
buildunity 2d
Add.List is not working
I tried to add monster to the List when they OnTriggerEnter an area, but If the monster spawn from inside the area, I cant add them in list, but Enqueue can add them in queue. Code is shown below. debug shows that it can detected the monsters spawned from inside the circle.
private List monsters = new List();
private Queue monsters1 = new Queue();
public void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Monster")
{
Debug.Log("findMonster");
monsters.Add(other.GetComponent<Monster>());
monsters1.Enqueue(other.GetComponent<Monster>());
}
}
Comment