Hello,
I did my heath and destroy detection a bit different. To me it seems more simple, but I wanted to ask if there is anything wrong with this method.
I created a variable called index. (The index position in the Sprite Sheet array).
I set this variable to -1 on start of the Brick instance.
On collision Exit 2D I have the following code.
GetComponent<AudioSource>().Play();
mHealth -= 1;
if (mHealth <= 0)
{
Destroy(gameObject);
levelM.deleteBrick(); // LevelM is the levelManager. I believe I handled this a bit different too.
}
else
{
++index;
this.GetComponent<SpriteRenderer>().sprite = brickSheet[index];
}
With this method, the index is increased, but as long as the brick doesnt have more hit points than it has images, it will always delete itself instead of increasing index position.