how to keep track of bricks broken

Hi I am currently working on a brick breaking game and need to keep track of when the ball breaks a brick. I was just using a counter that went up everytime it collided and added a script to -1 to the counter every time it hit an object that wasnt a brick. i understand that is not the best way especially cause it wont work. so i was hoping someone here knows how to. Also i am using C#.

How are you brick instantiated?

If you place them manually, then you know how many of them there are.

Create a static variable counter with that value that is decremented when you hit a brick.

If you instantiate them in a loop (double loop probably) in the start, then add a counter++ in each loop and decrement counter each time you hit a brick.

You can also use that variable to check if the scene is empty.

As I said, you know how many of them there is so you can do:

static var counter:int;
function Start(){
counter = numberOfBricks; }

numberOfBricks is a value you give.

Other possibilities is to tag the bricks as Bricks and use a function.

static var counter:int;
function Start(){
var brickArr:GameObject[];
brickArr = GameObject.FindGameObjectsWithTags("Brick"); 
counter = brickArr.Length,}