Accessing instances of an object (from other object)

Hello! I’m new to Unity. So far, developing with it has been fun. There is just this one problem I can’t figure out.

My game has bombs. I would like to be able to loop through their instances to access their information. There can be multiple exploding bombs on the screen, and from an enemy script, I would like to loop through each bomb instance and check, say, its position.

I couldn’t figure out the commands to use in the scripting manual. Any help would be appreciated.

My current solution is a global array which stores the bomb info. Each bomb writes its current status to this array. It works, but I bet there is a better way.

You would use the GetComponentsOfType(…) command to retrieve all bomb components, store them in an array and then loop over each element in the array. (you can access other components on said object too, for example the position through .transform.position and alike)

see the script reference for more information

Perfect, thank you! :slight_smile: That should do it.