One issue here is case-sensitivity in your Blueglassball.cs script.
OncollisionEnter2D
is not recognised by Unity because of your lower-case “c”, it should in fact be OnCollisionEnter2D
.
Regarding the bricks not breaking, it seems unlikely that just adding the one line for the AudioSource.PlayClipAtPoint
would prevent this, which suggest other issues.
I would consider adding a Debug.Log
statement on the first line of the OnCollisionEnter2D
method and output something of use to the console, this will help you to determine if this method is being called at all, for example;
void OnCollisionEnter2D(Collision2D col)
{
Debug.Log("OnCollisionEnter2D called in Brick.cs");
AudioSource.PlayClipAtPoint(crack, transform.position);
if(isBreakable)
{
HandledHits(); // note in the course this is named "HandleHits"
}
}
Run the game, if you see our message appear in the console then you are sure this method is being called. Assuming it is, I would then add another Debug.Log
statement to the first line within the HandledHits
method, and then finally within the LoadSprites
method.
Assuming all of these appear in the console you can be sure the code is calling the correct methods. After this I would perhaps look at things like, is it just the sprite that isn’t changing, have I added all of the sprites, have I made changes to an instance of a Brick instead of the Brick prefab.
Let me know how you get on with the above and post back any on going issues.
Note, you can just copy/paste your code into your posts which makes it a lot easier to work with, see the link below for how to apply formatting.
See also;