About 'Smarter maxHits Logic'!

In this video (objectives)…

  1. Remove blocks and recreate our playtesting level.
  2. Add code to provide a warning if our array is missing sprites.
  3. Remove the manual process for defining maxHits and link this to the array size of our sprites.

After watching (learning outcomes)… Add warnings to catch mistakes and remove one place we could make a mistake.

(Unique Video Reference: 32_BR_CUD)

We would love to know…

  • What you found good about this lecture?
  • What we could do better?

Remember that you can reply to this topic, or create a new topic. The easiest way to create a new topic is to follow the link in Resources. That way the topic will…

  • Be in the correct forum (for the course).
  • Be in the right sub-forum (for the section)
  • Have the correct lecture tag.

Enjoy your stay in our thriving community!

Rick,
A slight improvement on your debug output, so it says which array element was wrong:
private void ShowNextHitSprite()
{
int spriteIndex = timesHit - 1;

	if (hitSprites[spriteIndex] != null)
	{   // This element has a Sprite set in it
		GetComponent<SpriteRenderer>().sprite = hitSprites[spriteIndex];
	}   // if
	else
	{   // This element did not have a Sprite assign to it
		UnityEngine.Debug.LogError("Block Sprite is missing from array at element " + spriteIndex + " for " + gameObject.name);
	}   // else
}   // ShowNextHitSprite()

I had already implemented using Length to set my maxHits, but this is a good check in case someone increases the array of sprites and forgets to set one of more of them for that block. I have done it so that any block of a particular color has the same number of hits, so it is set in the prefab of that color. So only one place where you can make such a mistake, making it easy to fix, plus using the color to show which blocks need multiple hits works for Affordance as well. The color also is tied to the score value for the block, so another way to implement Affordance for the user so they know which blocks are better to hit.

Privacy & Terms