title: Unity OnCollisionEnter2D with multiple gameObjects
body: <p>Currently I am creating a brick breaker style game. In this there are two types of bricks. One is normal brick and another is a special brick. Normal brick gets destroyed on collision with ball. Special brick duplicates the ball and then gets destroyed.</p>
  <p>Now I have a check that whenever the remaining bricks gets to 0, game is over. I get the number of bricks at start and decrement the bricks on collision with ball.</p>
  <p>Issue is that sometimes, the remaining bricks gets to 0 even though I can see that there are few bricks in view. I thought it was due to 2 balls colliding the brick/special brick at same time. So I added hasCollided check and resetting in LateUpdate() to avoid that but issue still seems to happen.</p>
  <p>My code snippet:</p>
  <p>Ball.cs</p>
  <pre><code>void LateUpdate()
  {
      this.hasCollided = false;
      this.hasCollidedBrick = false;
  }
  private void OnCollisionEnter2D(Collision2D collision)
  {
      if(collision.gameObject.tag == &quot;Brick&quot;)
      {
          if(this.hasCollidedBrick == true){ return; }
          this.hasCollidedBrick = true;
          GameManager.instance.ScoreUp(5);
          Destroy(collision.gameObject);
      }
      else if(collision.gameObject.tag == &quot;SpecialBrick&quot;)
      {
          if(this.hasCollided == true){ return; }
          this.hasCollided = true;
          SceneGenerator.instance.remBalls++;
          GameManager.instance.ScoreUp(5);
          Destroy(collision.gameObject);
          clone = Instantiate(gameObject, transform.position,transform.rotation);
          
  
      }
  
  }
  </code></pre>
  <p>GameManager.cs</p>
  <pre><code>public void ScoreUp(int val)
  {
      score=score+val;
      if (val == 5)
      {
          remBricks--;
      }
      textScore.text = score.ToString();
      if (remBricks == 0)
      {
          winText.SetActive(true);
          textScore.gameObject.SetActive(false);
          isWin = true;
      }
  }
  </code></pre>
  <p>Also, I dynamically generate the bricks at start using Instantiate.</p>
  <p>Any help would be appreciated. Thanks!</p>