script to destroy after two hits

I’m working on a ballgame, where the ball shall destroy some bricks. But how should i write the script when i wants that the ball must hit the brick two times before the brick is destroyed.

The Script i have now is:

in the script for the brick.

void OnTriggerEnter() {
BallGame.SP.Hitbrick();
Destroy(gameObject);
}

In the script for the game

public void Hitbrick() {
bricksHit++;

if(bricksHit>=totalBricks) {
WonGame();
}
}

on the script for the brick you will need a counter for how many times the ball hits the brick.

private int timesHit = 0;
public int amountToDestroyBrick = 1;

void OnCollisionEnter(Collision hit){
      if(hit.gameObject.tag == ("ball"){
            timesHit++;
      }
}

void Update(){
      if(timeHit==amountToDestroyBrick){
            Destroy(gameObject);
      }
}

place that in a script which is attached to the brick you want to destroy and change the variable in the inspector window to how many times you want the brick to be hit. Hopefully should work but im doing my own thing at the moment so i can’t test. don’t forget to tag the ball with “ball” and place a ridgidbody on it

I’ve tried your code, but got a problem. Now the ball goes straight through the bricks

strange. i just tested it and it worked for me. are you sure that the ball is hitting the brick and not going behind it?

i don’t know whether this will helps or not .
put some delay on destroying the object,this will give enough time for physics to work.