In the video at about 3:00-3:10 there is this line
Image image = child?.GetComponent<Image>();
Now, we should be pretty certain that we have setup the staminaContainer
to contain a number of images that we can grab and not much else, but having a check can’t hurt either (and one might want to add some decoration between the stamina globes, although one would likely run into an issue with that decoration being images as well, so one would need some other way to differentiate between the stamina globes and the decoration).
But what happens in case we get a child object that is actually not an image we can grab the sprite
from?
if(...)
{ image.sprite = fullStaminaImage; }
else
{ image.sprite = emptyStaminaImage; }
Either of these assignments would fail if image
became null
from that GetComponent<>()
call…
So one would have to also check for this, as well…