[SOLVED] Two-hit Brick Not Displaying Damaged Sprite

UPDATE: Somehow I mananged to have an entire row of non-prefab two-hit bricks.

My setup is a little different. I have my own smoother looking brick that is replaced with the full brick sprite when it is hit. The weird thing is that my three-hit brick is working just fine, but the two-hit won’t update to damaged. The smooth sprite switches to damaged as it should, but the two hit never does.

public int maxHits;					// Holds how many times the brick can be hit
public Sprite[] damagedSprites;		// Array of damaged brick sprites
private int timesHit;				// Stores how many times the brick has been hit
private LevelManager levelManager;	// Instantiates a level manager

// Use this for initialization
void Start () 
{
	levelManager = GameObject.FindObjectOfType<LevelManager>();
	timesHit = 0;
}

void OnCollisionEnter2D (Collision2D collision)
{
	timesHit ++;

	if (timesHit >= maxHits)
	{
		Destroy(gameObject);
	}
	else
	{
		LoadSprites();
	}
}

void LoadSprites()
{
	int spriteIndex = timesHit - 1;	// Holds index of damaged sprite based on number of times original can be hit
	
	this.GetComponent<SpriteRenderer>().sprite = damagedSprites[spriteIndex];	
}

Thanks for any insights!

-Steel

Privacy & Terms