Hi,
I have a Brick breaker type of game in which all ‘bricks’ have a Collider2D component. When a ball collides with a brick i want to disable collisions for all the bricks temporarily. So i am doing
for (int i = 0; i < bricksList.Count; i++)
{
bricksList[i].GetComponent<Collider2D>().enabled = false;
}
when i detect ball-brick collision inside OnCollisionEnter2D.
However it still detects collision for multiple bricks if ball hits them (in between) at the same time . This is messing up my calculations. I want to have collision for only one brick. How do i achieve that?
I am just using a flag for now to detect if another collision happened with the same ball, but would like to know a better solution.
If you disable it, then all physics components are destroyed so you cannot get any collisions for it. TBH you’re not really explaining the problem very well above, namely:
What does this mean? Where you hit something has no bearing on whether you get a callback or not.
You don’t provide any information on how you’re detecting hits now, you only mention OnCollisionEnter2D but not where that script is. Info such as what is a “brick”? A GameObject with its own collider and script with the above physics callback? A tilemap? etc etc.