character lives

99073-untitled.png

my code works fine but for 3 lives I want 3 images of my character
How could I do this? any idea?

make a sprite with 3 life icon.
create an Image in your canvas.
coppy this settings (Image type : filled)
99078-capture.png

and change its fill amount in script something like this :

		if(lifeCount == 1)
gameObject.GetComponent<Image>().fillAmount = .33f;
		else if(lifeCount==2)
gameObject.GetComponent<Image>().fillAmount = .66f;
		else if(lifeCount==3)
gameObject.GetComponent<Image>().fillAmount = 1;

it may not best practise but works like charm without any headache

You could make a script that instantiate the images on the go. Like a “for” loop that puts every next image a little bit to the right. You don’t have/should do this inside the update, only when needed;

You could make your lives images children of an object with a HorizontalLayoutGroup component attached that will expand to hold your images. Just fiddle a bit with the LayoutGroup parameters.