Find the respawn objects and randomly spawn in one?

How could i do this because they are created randomly from another script, so I wont know how many there is and I wont be able to set it into the array variable in the script.

So i think i am going to have to use the gameObject.FindGameObjectWithTag("Respawn")?

How could i do this? I am stumped and confused

You should be able to add each object as they're created to an array, even if you don't know how many there will be.

Just add the object to the array right after its creation.

If you wanted to do the find method, take a look at GameObject.FindGameObjectsWithTag() make sure the "G" is capitalized for that. That will create an array of game objects that you can access.


If I understand correctly, the main problem you're having is that you can't assign an array to a prefab that doesn't yet exist in game.

What you can do is assign the list of respawn points to a static variable in a different script, and then reference that.

When you spawn your object, it doesn't have to be in the respawn point right away. You can instantiate it anywhere, perhaps out of view to be safe, and then let its script decide what to do next, E.G. randomly determine which respawn point to move itself to, referencing the static array of respawn points that was generated earlier.