So I am working on a game, aside from a game engine, and I have a for loop to detect collisions with all objects in a list of Panels
Here is the code:
for (int x = 1; x <= 2; x++)
{
if (player.obj.Bounds.IntersectsWith(walls[x].Bounds))
{
MessageBox.Show("COLLIDING");
}
}
Currently there are only two objects added to the list called walls
And everytime I go to run it tells me Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
I don't know what to do, am I setting up the if statement wrong?
I just tried taking it out of the for loop and replaced x with 0, and when I touched that object it said I was colliding, so I know I didn't set up the if statement wrong.