The crash you are getting is probably because you are removing objects from the list while iterating through it. This will modify the
Count of the list and the iterator will try to access elements that no longer exist.
The solution is to use a second list to which you add the objects that must be deleted.
for(int i = 0; i < bulletList.Count - 1; i++)
for(int j = i + 1; j < bulletList.Count; j++)
for(int i = 0; i < bulletsColliding.Count; i++)
Unfortunately, the problem with this is that you can get duplicates of bullets in your bullets colliding list if a bullet is colliding with more than one bullet at a time. Using C# lists the
Remove function will only return false though.
Using flags to set the bullets to
Alive or not can be a good idea to stop you from having to instanciate a Bullet if dead ones aleady exist. I would however just 'move' the bullets into a second list which is neither
Update()'d, and move them back when you need to create a new bullet, and the list isn't empty.
You must be very careful though that the Bullet instance is properly reset before you re-insert it into the working list.
To check the distance between bullets, you can use Pythagoras' theorem.
In 2D :
float Distance(Bullet a, Bullet b)
float xDistance = b.x - a.x;
float yDistance = b.y - a.y;
float sqDistance = (xDistance * xDistance) + (yDistance * yDistance);
In very time-critical sections, it is common to use squared positions of objects and not perform the square-root operation, as it is quite expensive.