U
U
userpyy2021-04-18 20:32:22
C++ / C#
userpyy, 2021-04-18 20:32:22

How to edit an array?

I have opponents that spawn on the level all the time. And each enemy after spawn tells the script a link to it.
I don't want to render every frame like this:

GameObject[] array = GameObject.FindGameObjectsWithTag("Enemy");

(While optimizing so to speak)
Now the question is:
How do I add to the GameObject array when the enemy spawns. And at his death to remove from there.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaly Kachan, 2021-04-19
@MANAB

Get a List in the class where you spawn (spawn manager). Do list.Add(newEnemy). the code needs to be removed call list.Remove(deadEnemy)

G
GavriKos, 2021-04-18
@GavriKos

It's not clear what the question is ... But I'll say right away - it's better to use List (at least) - it's easier with deletions and additions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question