Bricks not breaking after 2nd & 3rd hit // Transparent bricks


Two small technical issues here. Some of my bricks appear more transparent than others (see pics attached). It only started happening once I created Level 2 and Level 3. Anybody knows what’s doing this ?
On Level 2 the bricks are completely transparent. On Level 1 only some of them.

As for the Brick.cs script that makes the other blocks break after 2nd & 3rd hit:
It’s not working for me, all bricks break after 1st hit. If anybody has some advice on this, I would very much appreciate it. I’m a total newbie to Unity. Thx

Hi Alex,

Check the Z-index value in the Transform on the Brick prefabs…

From the look of your script you may not have got to the lecture yet which is responsible for changing the sprite based on the number of hits.


The Z Values are always the same for the bricks. (pics attached) I still don’t understand why some appear transparent. Especially since the problem only showed up once I created other levels (aka. Scenes)

As for the bricks. I’m at episode 82, the tutorial demontrates how the second row bricks break at the second hit and the top bricks at third hit. It’s just not working on mine.
The code for this is in brick.cs script, but I have to enter the ‘max hits’ in the brick (script) section of each brick in the Unity options. Screenshot is attached (showing 3 max hits for green bricks for ex.)
I tested it, it doesn’t take the ‘max hits’ into account. They all break at first hit.

1 Like

Hi Alex,

Other posts I’ve seen about the missing bricks usually end up either being the z-index of the brick, e.g. it’s actually behind the background image and in 2D view you can’t see it (you could check this by switching to 3D view in the scene moving around behind the background image). Or, if the sprites are actually missing from the sprites array.

Looking at the screen shots you’ve posted up, I can’t actually see the sprites array, so I’m guessing you haven’t got to that section yet, or, maybe you’ve missed a step?

Basically, there’s a sprite array added to the brick prefab (one for each of the colour bricks) which contains the relevant number of sprites for the stages of damage. So, a 1 hit brick has none, a 2 hit brick has 1 alternative image, a 3 hit brick has 2 alternative images etc.

From memory, in the code, it then reduces the size of the array each time the block is hit and swaps the image over.

I have just had a quick look at the course content and it looks like lectures 83 and 84 are going to cover the sprite sheets and swapping the images for you :slight_smile:

Updated Sun Jan 08 2017 19:14

On that first screenshot, the purple one, where you have the faded blocks, switch to Scene view and then select the appropriate faded block, can you pop a screenshot up of that, with the Inspector showing (and which block you have selected please).

Also, assuming none of the blocks are behind the background, try changing the z-index of the background to move it a bit further backwards.

The code for this is in brick.cs script, but I have to enter the ‘max hits’ in the brick (script) section of each brick in the Unity options.

Rather than changing this value on each instance of the bricks in the scene, change the value once on brick prefabs. Thus all green blocks become 2 hits, and so on.

To test for the collisions, after the timesHit++; statement on line 25, pop a Debug.Log("Brick hit!"); on line 26 (e.g not within the if statement. Does this appear in the console once the bricks in question are hit?

Hi Rob,

So I checked my game in 3D view, and I fixed the transparent blocks by placing the background a bit further away. I guess the background was interfering with some of the blocks. I stayed in 2D view while following all the tutorials, so I’m not sure how that came about…
But it’s fixed now :slight_smile: and checking 3D view is good to know in case I ever run into a similar issue again :slight_smile:

As for the number of hits, I did enter the numbers directly in the prefabs. Please see image attached.

I also entered Debug.Log(“Brick hit!”); on line 26. It does not appear in the console once the bricks are hit.

1 Like

So, we are getting closer then, thats good.

Transparency issue resolved.

But no collision detected, is this on all bricks, or only on a specific colour?

Can we also get another screen shot, with a brick prefab selected but with the 2D box collider component expanded in the Inspector please :slight_smile:

That’s on the bricks that are supposed to break on 2nd and 3rd hit. All existing bricks break at first hit.

Attached new screenshot :slight_smile:

Hi Alex,

Just want to check I understand the last remaining problem correctly. Earlier you mentioned all the bricks break on the first hit. Above you mentioned that it didnt display the message to the console when the collision occurs.

Can I assume its only the 1-hit bricks that are currently getting destroyed and for the 2-hot amd 3-hit bricks the ball just bounces off and doesn’t cause our collision message to be displayed to the console, but it does for the 1-hit bricks.

Can you confirm for me please - thanks :slight_smile:

Hi Rob,

My bad, there is a message displayed in the Console every time there’s a collision.

As for the bricks, they all disappear on first hit, even the ones that should disappear on hit 2 and hit 3. Sorry for the misunderstanding :slight_smile:
I hope it’s clear now

1 Like

Hi Alex,

Ok, so that’s good, collision is happening! Phew!..

Righty… what I would suggest doing now then is putting another Debug.Log() message inside the if statement logic you have in the OnCollisionEnter2D() method… e.g.

void OnCollisionEnter2D(Collision2D col) {


    Debug.Log("A collision was detected!");

    if (timesHit >= MaxHits) {
       Debug.Log("This block should be destroyed now! " + "Hits: " + timesHit + " MaxHits: " + MaxHits);


So, what should happen is that you get the first message when any collision is detected on any brick that has the Brick.cs script attached to it (via the prefabs). Then, if the number of times the brick has been hit exceeds the total required to destroy it, the second message should appear, and, ideally, the Brick should get destroyed, but lets just see if we can get the messages out.

Privacy & Terms