Y
Y
yraiv2022-03-05 22:33:28
Unity
yraiv, 2022-03-05 22:33:28

Removing and adding to list?

Am I understanding correctly or does it work differently?

When entering, I try to add an object to my list, and when I exit, remove it from there

void OnTriggerEnter2D(Collider2D collider)
    {
        if (collider.gameObject.tag == "Zombie")
        {
            zombieArray.Add(collider.gameObject);

        }
    }



 void OnTriggerExit2D(Collider2D collider)
    {
        zombieArray.Remove(collider.gameObject);

    }


He adds to add, but about deleting the question, will he delete the object that came out? and what will happen to the index, in case of deleting the value that was before? will it be equal to Null or just deleted?
Type, let's say 1,2.3,4, I delete the 2nd element, 1,3,4, remain?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2022-03-05
@yraiv

Yes, it's just that there won't be a deleted object in the list, the rest will move.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question